Tries to extract the message from an error response.
@param string $responseContents
@param string $fallbackMessage
@return string
507938
protected function extractMessageFromErrorResponse(string $responseContents, string $fallbackMessage): string
    {
        $result = $fallbackMessage;
        try {
            $errorResponse = $this->serializer->deserialize($responseContents, ErrorResponse::class, 'json');

            if ($errorResponse instanceof ErrorResponse) {
                $result = $errorResponse->getError()->getMessage();
            }
        } catch (Exception $e) {
            // Failed to decode error response.
        }
        return $result;
    }
58713
private static function createExceptionMessage(
        RequestException $previous,
        ResponseInterface $response = null
    ): string {
        if (!$response) {
            return $previous->getMessage();
        }

        try {
            $result = guzzle_json_decode((string) $response->getBody(), true);
            if (isset($result['message'])) {
                return $result['message'];
            }
        } catch (\InvalidArgumentException $e) {
            return $previous->getMessage();
        }

        return $previous->getMessage();
    }
1186559
public function headers($key = null, $fallback = null)
    {
        return $key
            ? $this->request->headers->get($key, $fallback)
            : $this->request->headers;
    }
726231
public function getCustomText($fallbackText = "Learn More") {
    if ($this->getAllowCustomText() && !empty($this->customText)) {
      return $this->customText;
    }

    $defaultText = $this->getDefaultText();
    return empty($defaultText)
      ? $fallbackText
      : $defaultText;
  }
1032599
def get_error_message(response_content):
    
    apache_regex = re.compile('.*<u>(.*)</u></p><p>.*')
    match = apache_regex.search(response_content)
    if match:
        error_message = match.group(1)
    else:
        local_regex = re.compile('.*<title>(.*)</title>.*')
        match = local_regex.search(response_content)
        if match:
            error_message = match.group(1)
        else:
            error_message = response_content
    return error_message
79746
private static function extractErrorDescription($exception)
    {
        $json = Client::responseToArray(
            $exception->getResponse()
        );
        if (isset($json['error_description'])) {
            return $json['error_description'];
        } elseif (isset($json['message'])) {
            return $json['message'];
        } else {
            return null;
        }
    }
476847
private function getExceptionMessage(\Exception $ex)
    {
        if ($ex instanceof RequestException && $ex->hasResponse()) {
            return (string) $ex->getResponse()->getBody();

            try {
                $this->jsonDecode($res);
                return $res;
            } catch (\InvalidArgumentException $e) {
                // no-op
            }
        }

        return $ex->getMessage();
    }
318677
public static void sendError(int errorCode, String errorContent) {
		HttpServletResponse response = Response.getServletResponse();
		try {
			if(HuluSetting.isDevMode) {
				response.sendError(errorCode);
			}else {
				response.sendError(errorCode, errorContent);
			}
		} catch (IOException e) {
			log.error(e, "Error when sendError!");
		}
	}
1349344
protected function getEmailAsPdf($fallbackEmailTo)
    {
        $emailAsPdf = array();
        $emailAsPdfSettings = $this->config->getEmailAsPdfSettings();
        if ($emailAsPdfSettings['emailAsPdf']) {
            $emailTo = !empty($emailAsPdfSettings['emailTo']) ? $this->getTokenizedValue($emailAsPdfSettings['emailTo']) : $fallbackEmailTo;
            if (!empty($emailTo)) {
                $emailAsPdf['emailto'] = $emailTo;
                $this->addTokenDefault($emailAsPdf, 'emailbcc', $emailAsPdfSettings['emailBcc']);
                $this->addTokenDefault($emailAsPdf, 'emailfrom', $emailAsPdfSettings['emailFrom']);
                $this->addTokenDefault($emailAsPdf, 'subject', $emailAsPdfSettings['subject']);
                $emailAsPdf['confirmreading'] = $emailAsPdfSettings['confirmReading'] ? Api::ConfirmReading_Yes : Api::ConfirmReading_No;
            }
        }
        return $emailAsPdf;
    }
1106961
public String parseErrorCode(HttpResponse response, JsonContent jsonContent) {
        String errorCodeFromHeader = parseErrorCodeFromHeader(response.getHeaders());
        if (errorCodeFromHeader != null) {
            return errorCodeFromHeader;
        } else if (jsonContent != null) {
            return parseErrorCodeFromContents(jsonContent.getJsonNode());
        } else {
            return null;
        }
    }
210451
protected function wrapHttpResponse(\Exception $exception, string $bodyContent): string
    {
        $body = fopen('php://temp', 'rw');
        fputs($body, $bodyContent);
        rewind($body);

        /** @var Response $response */
        $response = (new Response())
            ->withStatus($exception instanceof FlowException ? $exception->getStatusCode() : 500)
            ->withBody(new ContentStream($body))
            ->withHeader('Cache-Control', 'no-store');

        return implode("\r\n", $response->renderHeaders()) . "\r\n\r\n" . $response->getContent();
    }
996773
public function buildMessage(Request $request, Response $response, Throwable $err = null): string
    {
        $base = 'Error occurred while dispatching request';
        if ($err === null) {
            return $base;
        }

        return sprintf('%s:%s%s', $base, PHP_EOL, $err);
    }
928983
protected function jsonErrorResponse($errorMessage, $statusCode = 400, array $httpHeaders = array())
    {
        $statusTexts = \Symfony\Component\HttpFoundation\Response::$statusTexts;

        return $this->jsonResponse(array(
            'error' => (string) $errorMessage,
        ), array(
            'status' => array(
                'code'    => (int) $statusCode,
                'message' => $statusTexts[$statusCode],
            ),
        ), $httpHeaders);
    }
1020796
private function extractError($response)
    {
        $error = array();
        $response = json_decode($response);
        if (property_exists($response, 'error')) {
            if (is_string($response->error->message)) {
                $message = $response->error->message;
            } elseif (is_object($response->error->message)) {
                $message = $response->error->message->value;
            } else {
                $message = "Unknown error";
            }
            $error['Message'] = $message;
            return $error;
        }
        return null;
    }
1036604
public function locale(string $locale = null, ...$fallbackLocales)
    {
        if ($locale === null) {
            return $this->getLocalTranslator()->getLocale();
        }

        if (!$this->localTranslator || $this->localTranslator->getLocale() !== $locale) {
            $translator = Translator::get($locale);

            if (!empty($fallbackLocales)) {
                $translator->setFallbackLocales($fallbackLocales);

                foreach ($fallbackLocales as $fallbackLocale) {
                    $messages = Translator::get($fallbackLocale)->getMessages();

                    if (isset($messages[$fallbackLocale])) {
                        $translator->setMessages($fallbackLocale, $messages[$fallbackLocale]);
                    }
                }
            }

            $this->setLocalTranslator($translator);
        }

        return $this;
    }
100844
private function extractMessageContentData($messageContent)
    {
        $result = null;
        
        if ($messageContent instanceof \Exception) {
            
            // Handle log messages that are exceptions a little more
            // intelligently.
            // 
            // NOTE: In our limited testing, this is never used. Apparently
            //       something is converting the exceptions to strings despite
            //       the statement at
            //       http://www.yiiframework.com/doc-2.0/yii-log-logger.html#$messages-detail
            //       that the data could be an exception instance.
            //
            $result = array(
                'code' => $messageContent->getCode(),
                'exception' => $messageContent->getMessage(),
            );
            
            if ($messageContent instanceof \yii\web\HttpException) {
                $result['statusCode'] = $messageContent->statusCode;
            }
        } elseif ($this->isMultilineString($messageContent)) {
            
            // Split multiline strings (such as a stack trace) into an array
            // for easier reading in the log.
            $result = explode("\n", $messageContent);
            
        } else {
            
            // Use anything else as-is.
            $result = $messageContent;
        }
        
        return $result;
    }
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;
        }
    }