Some errors don't work as expected
ArthegaAsdweri opened this issue · 2 comments
ArthegaAsdweri commented
[PHPUnit\Framework\Exception] Undefined index: code
#1 vendor/fiskaly/fiskaly-sdk-php/src/errors/FiskalyErrorHandler.php:30
#2 vendor/fiskaly/fiskaly-sdk-php/src/FiskalyClient.php:307
public static function throwOnError($response)
{
if ($response instanceof ErrorResponse) {
if ($response->getCode() == self::$HTTP_ERROR) {
$responseData = $response->getData();
$errorBody = json_decode(base64_decode($responseData['response']['body']), true);
$requestId = $responseData['response']['headers']['x-request-id'][0];
throw new FiskalyHttpException($errorBody['message'], $errorBody['code'], $errorBody['error'], $errorBody['status_code'], $requestId);
} elseif ($response->getCode() == self::$HTTP_TIMEOUT_ERROR) {
throw new FiskalyHttpTimeoutException($response->getMessage());
} else {
throw new FiskalyClientException($response->getMessage(), $response->getCode(), $response->getData());
}
}
}
Some errors don't contain the key ['code']
ArthegaAsdweri commented
That's a possible result after debugging it. It only pops up randomly.
$errorBody = Array
(
[statusCode] => 429
[error] => Too Many Requests
[message] => Rate limit exceeded, retry in 1 minute
)
code is missing
status_code vs statusCode
prempador commented
Thanks for the report, see my answer here: fiskaly/fiskaly-sdk-dotnet#22 (comment)