Improve Sendcloud error handling
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\SendCloud;
|
||||
|
||||
use Exception;
|
||||
|
||||
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(
|
||||
$response['body']->error->message ?? '',
|
||||
$response['body']->error->code ?? 0
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user