Sendcloud error handling
This commit is contained in:
@@ -77,9 +77,9 @@ class SendCloudApi
|
||||
$response = $this->sendRequest($uri, null, true, ['parcel' => $parcel->toApiRequest()], [200,400]);
|
||||
switch ($response['code']) {
|
||||
case 200:
|
||||
if (isset($response->parcel))
|
||||
if (isset($response['body']->parcel))
|
||||
try {
|
||||
return ParcelResponse::fromApiResponse($response->parcel);
|
||||
return ParcelResponse::fromApiResponse($response['body']->parcel);
|
||||
} catch (Exception $e) {
|
||||
throw new SendcloudApiException(previous: $e);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ class SendcloudApiException extends Exception
|
||||
{
|
||||
public static function fromResponse(array $response) : SendcloudApiException {
|
||||
if (!isset($response['body']) || !is_object($response['body']))
|
||||
return new SendcloudApiException();
|
||||
return new SendcloudApiException(print_r($response,true));
|
||||
|
||||
return new SendcloudApiException(
|
||||
$response['body']->error->message ?? '',
|
||||
$response['body']->error->code ?? 0
|
||||
print_r($response['body'],true),
|
||||
$response['code']
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user