Skip to content

503 not catch properly #51

@IgorMijatovic

Description

@IgorMijatovic
{
    $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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions