/** * @param Response $response */ function __construct(Response $response) { $this->response = $response; if (($h = $response->getHeader("Content-Type", Header::class)) && $h->match("application/json", Header::MATCH_WORD) && ($failure = json_decode($response->getBody()))) { $message = $failure->message; if (isset($failure->errors)) { $this->errors = (array) $failure->errors; } } else { $message = trim($response->getBody()->toString()); } if (!strlen($message)) { $message = $response->getTransferInfo("error"); } if (!strlen($message)) { $message = $response->getResponseStatus(); } parent::__construct($message, $response->getResponseCode(), null); }