Sendcloud error handling

This commit is contained in:
Andreas Palm 2023-01-29 21:11:12 +01:00
parent 3fe2c7a5d9
commit 575ab86157
4 changed files with 7 additions and 7 deletions

View File

@ -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);
}

View File

@ -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']
);
}
}

View File

@ -353,7 +353,7 @@ abstract class Versanddienstleister
public function Paketmarke(string $target, string $docType, int $docId): void
{
$address = $this->GetAdressdaten($docId, $docType);
if (isset($_SERVER['HTTP_CONTENT_TYPE']) && ($_SERVER['HTTP_CONTENT_TYPE'] === 'application/json')) {
if (isset($_SERVER['CONTENT_TYPE']) && ($_SERVER['CONTENT_TYPE'] === 'application/json')) {
$json = json_decode(file_get_contents('php://input'));
$ret = [];
if ($json->submit == 'print') {

View File

@ -131,7 +131,7 @@ class Versandart_sendcloud extends Versanddienstleister
$ret->Errors[] = $result;
}
} catch (SendcloudApiException $e) {
$ret->Errors[] = $e->getMessage();
$ret->Errors[] = strval($e);
}
return $ret;
}