fiskaly/fiskaly-sdk-php

Some errors don't work as expected

ArthegaAsdweri opened this issue · 2 comments

[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']

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

Thanks for the report, see my answer here: fiskaly/fiskaly-sdk-dotnet#22 (comment)