set exception message from response

@param string $response
439684
public function setResponse($response)
    {
        $xml = simplexml_load_string($response);
        if (!empty($xml->error)) {
            $this->message = (string) $xml->error;
        }
    }
1310114
public function validateResponse($response)
    {
        if ($response === false) {
            throw new Exception(
                'Error reading data from the server.',
                Exception::SERVER_READ
            );
        }

        if ($response === 'BAD_FORMAT') {
            throw new Exception(
                'The client sent a command line that was not well-formed. ' .
                'This can happen if the line does not end with \r\n, if non-numeric ' .
                'characters occur where an integer is expected, if the wrong number of ' .
                'arguments are present, or if the command line is mal-formed in any other way.',
                Exception::BAD_FORMAT
            );
        }

        if ($response === 'OUT_OF_MEMORY') {
            throw new Exception(
                'The server cannot allocate enough memory for the job. The client should try again later.',
                Exception::OUT_OF_MEMORY
            );
        }

        if ($response === 'UNKNOWN_COMMAND') {
            throw new Exception(
                'The client sent a command that the server does not know.',
                Exception::UNKNOWN_COMMAND
            );
        }

        if ($response === 'INTERNAL_ERROR') {
            throw new Exception(
                'This indicates a bug in the server. It should never happen. ' .
                'If it does happen, please report it at http://groups.google.com/group/beanstalk-talk.',
                Exception::INTERNAL_ERROR
            );
        }

        return true;
    }
497377
protected function parseResponse(ResponseInterface $response)
    {
        $response = json_decode($response->getBody()->getContents());

        if (isset($response->success) && $response->success) {
            return $response->data;
        }

        throw new \Exception($response->error_info, $response->error_code);
    }
825055
public static function clientException(ResponseInterface $response, $data)
	{
		$message = $response->getReasonPhrase();

		// Use only the first error
		if ( isset($data['errors'][0]['detail']) )
		{
			$message = (string) $data['errors'][0]['detail'];
		}
		elseif ( isset($data['errors'][0]['title']) )
		{
			$message = (string) $data['errors'][0]['title'];
		}

		return static::fromResponse($response, $message);
	}
157460
public static function decodeHttpResponse($response) {
    $code = $response->getResponseHttpCode();
    $body = $response->getResponseBody();
    $decoded = null;
    
    if ($code != '200' && $code != '201' && $code != '204') {
      $decoded = json_decode($body, true);
      $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
      if ($decoded != null && isset($decoded['error']['message'])  && isset($decoded['error']['code'])) {
        // if we're getting a json encoded error definition, use that instead of the raw response
        // body for improved readability
        $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}";
      } else {
        $err .= ": ($code) $body";
      }
      throw new Service\Exception($err, $code);
    }
    
    // Only attempt to decode the response, if the response code wasn't (204) 'no content'
    if ($code != '204') {
      $decoded = json_decode($body, true);
      if ($decoded == null) {
        throw new Service\Exception("Invalid json in service response: $body");
      }
    }
    return $decoded;
  }
301190
public static function failedCompletelyException($response)
    {
        $message = '';
        foreach ($response as $key => $item) {
            if ($item['status'] === 'error') {
                $message .= $key == 0? "" : "\r\n";
                $message .= $item['message'];
            }
        }

        return new static($message);
    }
413084
public function setResponse($response)
    {
        if (is_string($response) && class_exists($response)) {
            $response = new $response();
            if (!$response instanceof Zend_Amf_Response) {
                require_once 'Zend/Amf/Server/Exception.php';
                throw new Zend_Amf_Server_Exception('Invalid response class');
            }
        } elseif (!$response instanceof Zend_Amf_Response) {
            require_once 'Zend/Amf/Server/Exception.php';
            throw new Zend_Amf_Server_Exception('Invalid response object');
        }
        $this->_response = $response;
        return $this;
    }
1319330
public void setResponse(JsonRpcResponse response) {
    if (response.isError()) {
      setException(response.error());
      return;
    }

    try {
      set((V) Messages.fromJson(method.outputBuilder(), response.result()));
    } catch (Exception e) {
      setException(e);
    }
  }
877283
private function decodeResponse(string $response)
    {
        if (strpos($response, '!') !== false) {
            throw new \Exception($response);
        }

        return new BotScoutResponse($response);
    }
1047826
private function checkResponse($response)
    {
        $hasRequestError = false;
        if (preg_match('/4\d\d/', $response->getStatusCode())) {
            $this->log('error', "Invalid API key or password");
            $this->addError(self::ERROR_HTTP_AUTHENTICATION_ERROR, false);
            $hasRequestError = true;
        } elseif (preg_match('/5\d\d/', $response->getStatusCode())) {
            $this->log('error', "Gateway error - HTTP " . $response->getStatusCode());
            $this->addError(self::ERROR_HTTP_SERVER_ERROR);
            $hasRequestError = true;
        } elseif ($response->getError()) {
            $this->log('error', "Connection error: " . $response->getError());
            $this->addError(self::ERROR_CONNECTION_ERROR);
            $hasRequestError = true;
        }

        if ($hasRequestError) {
            throw new RequestException(sprintf("Last HTTP response status code: %s", $response->getStatusCode()));
        }
    }
400557
protected function setResponseError($error, int $statusCode = 500) : void
    {
        if ($error instanceof \Exception) {
            $error = $error->getMessage();
        }

        $this->response['message'] = (string)$error;
        $this->response['status'] = $statusCode;
    }
71866
public function setError($msg, Exception $cause = null)
    {
        if ($this->errmsg === null) {
            $this->errmsg = $msg;
            $this->cause = $cause;
        }
    }
163062
public function isValid($response)
    {
        if (is_null($this->secretKey))
            throw new \Exception('You must set your secret key');

        if (empty($response)) {

            $this->errorCodes = array('internal-empty-response');

            return false;
        }

        $params = array(
            'secret'   => $this->secretKey,
            'response' => $response,
            'remoteip' => $this->remoteIp,
        );

        $url = self::VERIFY_URL.'?'.http_build_query($params);

        if (function_exists('curl_version'))
        {
            $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, $this->verifyTimeout);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            $response = curl_exec($curl);
        }
        else
        {
            $response = file_get_contents($url);
        }

        if (empty($response) || is_null($response) || !$response)
        {
            return false;
        }

        $json = json_decode($response, true);

        if (isset($json['error-codes']))
        {
            $this->errorCodes = $json['error-codes'];
        }

        return $json['success'];
    }
209466
public function setException(exception $e)
    {
        if (isset($this->response)) {
            $this->response->setException($e);
        } else {
            throw $e;
        }
    }
168681
public static function clientException(ResponseInterface $response, $data)
    {
        $message = $response->getReasonPhrase();
        $code = $response->getStatusCode();
        $body = (string) $response->getBody();

        if (isset($data['meta'], $data['meta']['error_message'])) {
            $message = $data['meta']['error_message'];
        }
        if (isset($data['meta'], $data['meta']['code'])) {
            $code = $data['meta']['code'];
        }

        return new static($message, $code, $body);
    }
341515
private function unserializeResponse($response)
    {
        $result = unserialize($response);
        if ($response !== 'b:0;' && $result === false) {
            throw new \Exception(substr($response, 0, 5000));
        }

        return $result;
    }
1065864
private static function handleErrors($response)
    {
        switch ($response->getStatusCode()) {
            case 200:
                return json_decode($response->getBody());
                break;
            case 401:
                throw new UnauthorizedException('Unauthorized (Invalid API key or insufficient permissions)');
                break;
            case 404:
                throw new NotFoundException('Object not found within your account scope');
                break;
            case 406:
                throw new InvalidFormatException('Requested format is not supported - request JSON or XML only');
                break;
            case 422:
                throw new ValidationException('Validation error(s) for create or update method');
                break;
            case 500:
                throw new ServerException('Something went wrong on Challonge\'s end');
                break;
            default:
                $decodedResponse = json_decode($response->getBody());
                throw new UnexpectedErrorException($decodedResponse);
                break;
        }
    }