0 follower

Final Class Yiisoft\ErrorHandler\Renderer\JsonRenderer

InheritanceYiisoft\ErrorHandler\Renderer\JsonRenderer
ImplementsYiisoft\ErrorHandler\ThrowableRendererInterface

Formats throwable into JSON string.

Constants

Hide inherited constants

Constant Value Description Defined By
CONTENT_TYPE 'application/json' Yiisoft\ErrorHandler\Renderer\JsonRenderer
DEFAULT_ERROR_MESSAGE 'An internal server error occurred.' Yiisoft\ErrorHandler\ThrowableRendererInterface

Method Details

Hide inherited methods

render() public method

public Yiisoft\ErrorHandler\ErrorData render ( Throwable $t, \Psr\Http\Message\ServerRequestInterface|null $request null )
$t Throwable
$request \Psr\Http\Message\ServerRequestInterface|null

                public function render(Throwable $t, ?ServerRequestInterface $request = null): ErrorData
{
    return new ErrorData(
        json_encode(
            [
                'message' => self::DEFAULT_ERROR_MESSAGE,
            ],
            JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES
        ),
        [Header::CONTENT_TYPE => self::CONTENT_TYPE],
    );
}

            
renderVerbose() public method

public Yiisoft\ErrorHandler\ErrorData renderVerbose ( Throwable $t, \Psr\Http\Message\ServerRequestInterface|null $request null )
$t Throwable
$request \Psr\Http\Message\ServerRequestInterface|null

                public function renderVerbose(Throwable $t, ?ServerRequestInterface $request = null): ErrorData
{
    return new ErrorData(
        json_encode(
            [
                'type' => $t::class,
                'message' => $t->getMessage(),
                'code' => $t->getCode(),
                'file' => $t->getFile(),
                'line' => $t->getLine(),
                'trace' => $t->getTrace(),
            ],
            JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR
        ),
        [Header::CONTENT_TYPE => self::CONTENT_TYPE],
    );
}