Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FlattenException.php

function FlattenException::createFromThrowable

6 calls to FlattenException::createFromThrowable()
ErrorListener::logKernelException in vendor/symfony/http-kernel/EventListener/ErrorListener.php
ErrorListener::onControllerArguments in vendor/symfony/http-kernel/EventListener/ErrorListener.php
ErrorListener::onKernelException in vendor/symfony/http-kernel/EventListener/ErrorListener.php
FlattenException::create in vendor/symfony/error-handler/Exception/FlattenException.php
FlattenException::createWithDataRepresentation in vendor/symfony/error-handler/Exception/FlattenException.php

... See full list

File

vendor/symfony/error-handler/Exception/FlattenException.php, line 50

Class

FlattenException
FlattenException wraps a PHP Error or Exception to be able to serialize it.

Namespace

Symfony\Component\ErrorHandler\Exception

Code

public static function createFromThrowable(\Throwable $exception, ?int $statusCode = null, array $headers = []) : static {
    $e = new static();
    $e->setMessage($exception->getMessage());
    $e->setCode($exception->getCode());
    if ($exception instanceof HttpExceptionInterface) {
        $statusCode = $exception->getStatusCode();
        $headers = array_merge($headers, $exception->getHeaders());
    }
    elseif ($exception instanceof RequestExceptionInterface) {
        $statusCode = 400;
    }
    $statusCode ??= 500;
    if (class_exists(Response::class) && isset(Response::$statusTexts[$statusCode])) {
        $statusText = Response::$statusTexts[$statusCode];
    }
    else {
        $statusText = 'Whoops, looks like something went wrong.';
    }
    $e->setStatusText($statusText);
    $e->setStatusCode($statusCode);
    $e->setHeaders($headers);
    $e->setTraceFromThrowable($exception);
    $e->setClass(get_debug_type($exception));
    $e->setFile($exception->getFile());
    $e->setLine($exception->getLine());
    $previous = $exception->getPrevious();
    if ($previous instanceof \Throwable) {
        $e->setPrevious(static::createFromThrowable($previous));
    }
    return $e;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal