Get the error message from the response if present.

@param \Psr\Http\Message\ResponseInterface $response

@return string|null
171470
private static function getMessage(ResponseInterface $response)
    {
        try {
            if ($error = ResponseMediator::getContent($response)['error'] ?? null) {
                if ($message = $error['message'] ?? null) {
                    if ($detail = $error['detail'] ?? null) {
                        return sprintf('%s: %s', $message, strtok($detail, "\n"));
                    } else {
                        return $message;
                    }
                }
            }
        } catch (DecodingFailedException $e) {
            // return nothing
        }
    }
106216
public function getError() : ?string 
    {
        if ( ! $this->hasError()) {
            $this->setError($this->getDefaultError());
        }
        return $this->error;
    }
1282472
private function processError(ResponseInterface $response, array $arguments): ResponseInterface
    {
        if (is_callable($this->options["error"])) {
            $handler_response = $this->options["error"]($response, $arguments);
            if ($handler_response instanceof ResponseInterface) {
                return $handler_response;
            }
        }
        return $response;
    }
1052795
def _get_error_message(response):
    """"""
    try:
        data = response.json()
        if "error_description" in data:
            return data['error_description']
        if "error" in data:
            return data['error']
    except Exception:
        pass

    return "Unknown error"
1108111
protected function errorResponse(ServerRequestInterface $request, ResponseInterface $response)
    {
        if (
            interface_exists(GlobalEnvironmentInterface::class, false) &&
            $response instanceof GlobalEnvironmentInterface &&
            $response->isStale()
        ) {
            $response = $response->revive();
        }

        $errorResponse = $response->withProtocolVersion($request->getProtocolVersion())->withStatus(500);
        $errorResponse->getBody()->write('An unexpected error occured');

        return $errorResponse;
    }
702370
public function getErrorMessage()
    {
        if (array_key_exists('error', $this->responseData?: [])) {
            if (is_string($this->responseData['error'])) {
                return json_encode($this->responseData['error']);
            } elseif(array_key_exists('error', $this->responseData['error'])) {
                return json_encode($this->responseData['error']['error']);
            } else {
                return json_encode($this->responseData['error']);
            }
        } else {
            return null;
        }
    }
988994
protected function fetchResponseError($response)
	{
		if (isset($response['errors'])) {
			$first = reset($response['errors']);
			return [
				'code' => $first['code'],
				'message' => $first['message'],
			];
		}
		return null;
	}
902250
private function fetchErrorMessages(ResponseInterface $response): array
    {
        $responseBody = $response->getBody();
        $responseBodyInJson = json_decode($responseBody, true);

        if ($this->doesResponseBodyContainValidJson($responseBodyInJson)) {
            return $this->fetchAllErrorDescription($responseBodyInJson);
        } else {
            return [$responseBody];
        }
    }
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);
    }
631164
private function decodeResponse( ResponseInterface $response ) {
		$resultArray = json_decode( $response->getBody(), true );

		$this->logWarnings( $resultArray );
		$this->throwUsageExceptions( $resultArray );

		return $resultArray;
	}
453441
public function checkResponse(ResponseInterface $response)
    {
        if (isset($this->_errorChecker)) {
            $error = call_user_func($this->_errorChecker, $response);
        } else {
            $error = $this->getResponseError($response);
        }

        if ($error) {
            throw new ResponseErrorException($error, $response);
        }
    }
269482
protected function checkErrorResponse(ResponseInterface $response)
    {
        $statusCode = $response->getStatusCode();
        if (200 <= $statusCode && $statusCode < 299) {
            if (!$response->getBody()->getSize()) {
                throw new BadResponseException('unexpected empty body');
            }

            return;
        }

        // Mitake API always return status code 200
        throw new BadResponseException(sprintf('unexpected status code: %d', $statusCode));
    }
1319594
protected function returnResponse(ResponseInterface $response): ResponseInterface
    {
        $this->nextHandler = null;
        reset($this->handlers);
        return $response;
    }
680692
protected function getContentType(ResponseInterface $response)
    {
        // Check for an accept header
        if ($response->hasHeader('Content-Type')) {
            // Get the first part of the header, for example: exclude charset=utf-8

            $header = $response->getHeaderLine('Content-Type');
            $parts = explode(';', $header);
            return trim($parts[0]);
        }

        return null;
    }
175846
private function determineErrorResponse(
        $exception,
        $message,
        ResponseInterface $response,
        ServerRequestInterface $request
    )
    {
        $applicationEvent = $this->getApplicationEvent();
        $applicationEvent->setName(self::EVENT_LIFECYCLE_ERROR);
        $applicationEvent->setRequest($request);
        $applicationEvent->setResponse($response);
        $applicationEvent->setErrorResponse($this->getResponse());

        $this->emit($applicationEvent, $exception);

        $errorResponse = $applicationEvent->getErrorResponse();

        if (!$errorResponse->getBody()->isWritable()) {
            return $errorResponse;
        }

        $content = $errorResponse->getBody()->__toString();
        if (empty($content)) {
            $errorResponse->getBody()->write($message);
        }

        return $errorResponse;
    }
382881
public function getResponseId($response){
        $isError = $this->isError($response);

        if($isError){
            $result = array (
                'message' => $response->getMessage(),
                'eventId' => $response->getEventId()
            );

            return $result;

        } else {
            $result = array (
                'responseMessage' => $response->getResponseMessage(),
                'id' => $response->getId()
            );

            return $result;
        }
    }
828765
public function get_error_message($rule)
	{
		if (isset($this->error_messages[$rule]))
		{
			return $this->error_messages[$rule];
		}
		elseif (isset($this->error_messages[0]))
		{
			return $this->error_messages[0];
		}

		return null;
	}