Improve Sendcloud error handling

This commit is contained in:
Andreas Palm
2022-11-02 22:37:04 +01:00
parent 1c7e84d8f2
commit d676a1b09a
4 changed files with 122 additions and 61 deletions
@@ -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
);
}
}