private function parseExceptionForErrorMessages(Exception $exception)
    {
        if (! $exception instanceof BadResponseException) {
            return new ApiException($exception->getMessage(), 0, $exception);
        }

        $response = $exception->getResponse();

        if (null === $response) {
            return new ApiException('Response is NULL.', 0, $exception);
        }

        Psr7\rewind_body($response);
        $responseBody = $response->getBody()->getContents();
        $decodedResponseBody = json_decode($responseBody, true);

        if (null !== $decodedResponseBody && isset($decodedResponseBody['error']['message']['value'])) {
            $errorMessage = $decodedResponseBody['error']['message']['value'];
        } else {
            $errorMessage = $responseBody;
        }

        $this->checkWhetherRateLimitHasBeenReached($response, $errorMessage);

        return new ApiException('Error ' . $response->getStatusCode() . ': ' . $errorMessage, $response->getStatusCode(), $exception);
    }
private function parseExceptionForErrorMessages(Exception $exception)
    {
        if (! $exception instanceof BadResponseException) {
            return new ApiException($exception->getMessage(), 0, $exception);
        }

        $response = $exception->getResponse();

        if (null === $response) {
            return new ApiException('Response is NULL.', 0, $exception);
        }

        Psr7\rewind_body($response);
        $responseBody = $response->getBody()->getContents();
        $decodedResponseBody = json_decode($responseBody, true);

        if (null !== $decodedResponseBody && isset($decodedResponseBody['error']['message']['value'])) {
            $errorMessage = $decodedResponseBody['error']['message']['value'];
        } else {
            $errorMessage = $responseBody;
        }

        $this->checkWhetherRateLimitHasBeenReached($response, $errorMessage);

        return new ApiException('Error ' . $response->getStatusCode() . ': ' . $errorMessage, $response->getStatusCode(), $exception);
    }
private function parseExceptionForErrorMessages ( Exception $ exception ) { if ( ! $ exception instanceof BadResponseException ) { return new ApiException ( $ exception -> getMessage ( ) , 0 , $ exception ) ; } $ response = $ exception -> getResponse ( ) ; if ( null === $ response ) { return new ApiException ( 'Response is NULL.' , 0 , $ exception ) ; } Psr7 \ rewind_body ( $ response ) ; $ responseBody = $ response -> getBody ( ) -> getContents ( ) ; $ decodedResponseBody = json_decode ( $ responseBody , true ) ; if ( null !== $ decodedResponseBody && isset ( $ decodedResponseBody [ 'error' ] [ 'message' ] [ 'value' ] ) ) { $ errorMessage = $ decodedResponseBody [ 'error' ] [ 'message' ] [ 'value' ] ; } else { $ errorMessage = $ responseBody ; } $ this -> checkWhetherRateLimitHasBeenReached ( $ response , $ errorMessage ) ; return new ApiException ( 'Error ' . $ response -> getStatusCode ( ) . ': ' . $ errorMessage , $ response -> getStatusCode ( ) , $ exception ) ; }
Parse the response in the Exception to return the Exact error messages.

@param Exception $exception

@return \Picqer\Financials\Moneybird\Exceptions\ApiException

@throws \Picqer\Financials\Moneybird\Exceptions\Api\TooManyRequestsException
Parse the response in the Exception to return the Exact error messages .