Kelunik\Acme\AcmeService::generateException PHP Method

generateException() private method

Generates a new exception using the response to provide details.
private generateException ( Amp\Artax\Response $response ) : AcmeException
$response Amp\Artax\Response HTTP response to generate the exception from
return AcmeException exception generated from the response body
    private function generateException(Response $response)
    {
        $body = $response->getBody();
        $status = $response->getStatus();
        $info = json_decode($body);
        $uri = $response->getRequest()->getUri();
        if (isset($info->type, $info->detail)) {
            return new AcmeException("Invalid response: {$info->detail}.\nRequest URI: {$uri}.", $info->type);
        }
        return new AcmeException("Invalid response: {$body}.\nRequest URI: {$uri}.", $status);
    }