Extracts the exception message.

@param \Exception $exception
@param int|null   $statusCode

@return string
515603
protected function getExceptionMessage(\Exception $exception, $statusCode = null)
    {
        $showMessage = $this->messagesMap->resolveException($exception);

        if ($showMessage || $this->debug) {
            return $exception->getMessage();
        }

        return array_key_exists($statusCode, Response::$statusTexts) ? Response::$statusTexts[$statusCode] : 'error';
    }
1314580
protected function _getMessage(Exception $exception)
    {
        $message = $this->getMessageForException($exception);

        $request = Router::getRequest();
        if ($request) {
            $message .= $this->_requestContext($request);
        }

        return $message;
    }
444016
protected function getExceptionAsXml(Throwable $exception): string
	{
		$details = $this->getStatusCodeAndMessage($exception);

		$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><error />");

		$xml->addChild('code', $details['code']);

		$xml->addChild('message', $details['message']);

		return $xml->asXML();
	}
221129
protected function getBacktrace(\Exception $exception)
    {
        $backtrace = array();

        $backtrace[] = '---';
        $backtrace[] = $this->getErrorMessage($exception);
        $backtrace[] = '---';

        // Allow marshalling of the trace: PHP marks getTraceAsString as final :-(
        if (method_exists($exception, 'getPreviousTraceAsString')) {
            $backtrace = array_merge($backtrace, explode("\n", $exception->getPreviousTraceAsString()));
        } else {
            $backtrace = array_merge($backtrace, explode("\n", $exception->getTraceAsString()));
        }

        if (($previous = $exception->getPrevious())) {
            $backtrace = array_merge($backtrace, $this->getBacktrace($previous)); // Recurse
        }

        return $backtrace;
    }
1043083
protected function getErrorMessage(Exception $exception)
    {
        $defaultMessage =  __('Unexpected error. Please contact administrator');
        if (DEBUG_MODE) {
            $defaultMessage = $exception->getMessage();
        }
        return ($exception instanceof common_exception_UserReadableException) ? $exception->getUserMessage() :  $defaultMessage;
    }
1358547
protected function createResponseData(Exception $exception)
    {
        return $this->debug
            ? $this->extractExceptionData($exception)
            : $this->createDefaultResponseData($exception);
    }
538923
protected function decorateException(\Exception $e, $status) {

		$headerTpl = '
		<!DOCTYPE html>
		<html>
			<head>
				<title>Error %d</title>
				<meta http-equiv="content-type" content="text/html; charset=UTF-8">
			</head>
			<body>
				<table>
					<tr>
						<th colspan="4">%s</th>
					</tr>
					<tr>
						<th></th>
						<th>File</th>
						<th>Line</th>
						<th>Function</th>
					</tr>
		';

		$footerTpl = '				
				</table>
			</body>
		</html>';

		$rowTpl = '<tr><td>%d</td><td>%s</td><td>%d</td><td>%s</td></tr>';

		$content = sprintf($headerTpl, $status, $e->getMessage());

		foreach($e->getTrace() as $ndx => $level) {
			
			// skip row with error handler

			if($ndx) {
				$content .= sprintf(
					$rowTpl,
					$ndx,
					$level['file'],
					$level['line'],
					(isset($level['class']) ? ($level['class'] . $level['type'] . $level['function']) : $level['function']) . '()'
				);
			}
		}

		$content .= $footerTpl;

		return $content;

	}
1152121
public function formatException(Exception $exception)
    {
        if ($exception instanceof HttpException) {
            return $this->formatter->formatResponse($exception->getResponse());
        }

        if ($exception instanceof TransferException || $exception instanceof NetworkExceptionInterface) {
            return sprintf('Transfer error: %s', $exception->getMessage());
        }

        return sprintf('Unexpected exception of type "%s": %s', get_class($exception), $exception->getMessage());
    }
642095
private function getNotificationMessage(Throwable $exception): string
    {
        if ($exception instanceof HttpExceptionInterface) {
            return $exception->getMessage();
        }

        $file = new SplFileInfo($exception->getFile());
        $line = $exception->getLine();

        $relativePathname = (new Filesystem())->makePathRelative($file->getPath(), $this->rootDir) . $file->getFilename();

        $message = $exception->getMessage();

        return sprintf('%s [in %s:%d]', $message, $relativePathname, $line);
    }
1149375
protected function getDevelopmentEnvironmentContent(Exception $ex, int $statusCode) : string
    {
        ob_start();

        if ($statusCode === 503) {
            require __DIR__ . "/templates/{$this->getRequestFormat()}/MaintenanceMode.php";
        } else {
            require __DIR__ . "/templates/{$this->getRequestFormat()}/DevelopmentException.php";
        }

        return ob_get_clean();
    }
1338106
public function getCode(Exception $exception)
    {
        if (method_exists($exception, 'getCode') && $code = $exception->getCode())
            return $code;

        if (method_exists($exception, 'getStatusCode') && $code = $exception->getStatusCode())
            return $code;

        return null;
    }
855300
private function parseExceptionForErrorMessages(Exception $exception)
    {
        if (! $exception instanceof BadResponseException) {
            return new ApiException($exception->getMessage(), 0, $exception);
        }

        $response = $exception->getResponse();

        if (null === $response) {
            return new ApiException('Response is NULL.', 0, $exception);
        }

        Psr7\rewind_body($response);
        $responseBody = $response->getBody()->getContents();
        $decodedResponseBody = json_decode($responseBody, true);

        if (null !== $decodedResponseBody && isset($decodedResponseBody['error']['message']['value'])) {
            $errorMessage = $decodedResponseBody['error']['message']['value'];
        } else {
            $errorMessage = $responseBody;
        }

        $this->checkWhetherRateLimitHasBeenReached($response, $errorMessage);

        return new ApiException('Error ' . $response->getStatusCode() . ': ' . $errorMessage, $response->getStatusCode(), $exception);
    }
575329
protected function transformByStatusCodeAndName(
        \Throwable $exception,
        $errorStatusCode,
        $errorStatusName
    ): ApiException {
        foreach ($this->supportedApiExceptions as $apiExceptionClass) {
            $statusCode = \constant($apiExceptionClass . '::STATUS_CODE');
            $statusName = \constant($apiExceptionClass . '::STATUS_NAME');
            if ($errorStatusCode === $statusCode && $errorStatusName === $statusName) {
                return new $apiExceptionClass($exception);
            }
        }

        return new ApiException($exception);
    }
14774
protected static function extractOriginalExceptionMessage(ClientException $exception)
    {
        self::$response = $exception->getResponse();
        self::$stream = self::$response->getBody();
        self::$content = self::$stream->getContents();
        if (!self::$content) {
            throw new InstagramServerException(
                $exception->getMessage(),
                $exception->getCode(),
                $exception
            );
        }

        return json_decode(self::$content);
    }
859686
public function setStatusCode($statusCode)
    {
        $statusCode = (int)$statusCode;
        if ($statusCode < 100 || $statusCode >= 600) {
            throw new \Exception("Invalid status code: {$statusCode}.");
        }
        $this->statusCode = $statusCode;
        return $this;
    }
615633
private function eventMsg(\Exception $exception)
    {
        return sprintf('%s (%s line:%s)', $exception->getMessage(), $exception->getFile(), $exception->getLine());
    }
957799
protected function getItemTextMessage($exception)
    {
    	$text = sprintf('Type: %s' . PHP_EOL, get_class($exception));
    	
    	if (($code = $exception->getCode())) {
    		$text .= sprintf('Code: %s' . PHP_EOL, $code);
    	}
    	
    	if (($message = $exception->getMessage())) {
    		$text .= sprintf('Message: %s' . PHP_EOL, htmlentities($message));
    	}
    	
    	if (($file = $exception->getFile())) {
    		$text .= sprintf('File: %s' . PHP_EOL, $file);
    	}
    	
    	if (($line = $exception->getLine())) {
    		$text .= sprintf('Line: %s' . PHP_EOL, $line);
    	}
    	
    	if (($trace = $exception->getTraceAsString())) {
    		$text .= sprintf('Trace: ' . PHP_EOL. '%s', $trace);
    	}
    	
    	return $text;
    }