Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

503 not catch properly #51

Open
IgorMijatovic opened this issue Jan 27, 2020 · 0 comments
Open

503 not catch properly #51

IgorMijatovic opened this issue Jan 27, 2020 · 0 comments

Comments

@IgorMijatovic
Copy link

{
    $headers = array('Content-Type: application/json', 'X-WSSE: ' . $this->getAuthenticationSignature());
    $uri = $this->baseUrl . $uri;

    try {
        $responseJson = $this->client->send($method, $uri, $headers, $body);
    } catch (\Exception $e) {
        throw new ServerException($e->getMessage());
    }

    $responseArray = json_decode($responseJson, true);

    if ($responseArray === null) {
        switch (json_last_error()) {
            case JSON_ERROR_DEPTH:
                throw new ClientException('JSON response could not be decoded, maximum depth reached.');
            default:
                throw new ServerException("JSON response could not be decoded:\n" . json_last_error_msg());
        }
    }

    if (is_array($responseArray) === false) {
        throw new ServerException("JSON response is not an array:\n" . $responseArray);
    }

    return new Response($responseArray);
}

in responseJson i got ofter and ofter response
"

503 Service Unavailable

No server is available to handle this request. ";

after json_decode
$responseArray = null and then we throw Exception throw new ServerException("JSON response could not be decoded:\n" . Instead there is no problem with Json encode, there is problem with server and i would rather throw ServerException with payload, methods, uri info :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant