Skip to content

Commit

Permalink
Bugfix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sweikert committed Feb 10, 2022
1 parent 28a1cac commit ad3da96
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/HttpAdapter/CurlOroHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,23 @@ protected function parseResponseBody($response, $statusCode, $httpBody): ?stdCla
}

if ($statusCode >= 400) {
$message = "Error executing API call ({$body->status}: {$body->title}): {$body->detail}";

$field = null;
$message = "Unknown Error executing API call";

if (! empty($body->field)) {
$field = $body->field;
}
if (! empty($body->errors)) {
$message = "Error executing API call ({$body->errors[0]->status}: {$body->errors[0]->title})";

if (! empty($body->errors[0]->detail)) {
$message .= ": {$body->errors[0]->detail}";
}

if (! empty($body->errors[0]->field)) {
$field = $body->errors[0]->field;
}

if ($httpBody) {
$message .= ". Request body: {$httpBody}";
if ($httpBody) {
$message .= ". Request body: {$httpBody}";
}
}

throw new ApiException($message, $statusCode, $field);
Expand Down

0 comments on commit ad3da96

Please sign in to comment.