Class WebExceptionRenderer
Web Exception Renderer.
Captures and handles all unhandled exceptions. Displays helpful framework errors when debug is true. When debug is false, WebExceptionRenderer will render 404 or 500 errors. If an uncaught exception is thrown and it is a type that WebExceptionHandler does not know about it will be treated as a 500 error.
Implementing application specific exception rendering
You can implement application specific exception handling by creating a subclass of
WebExceptionRenderer and configure it to be the exceptionRenderer
in config/error.php
Using a subclass of WebExceptionRenderer
Using a subclass of WebExceptionRenderer gives you full control over how Exceptions are rendered, you can configure your class in your config/app.php.
Property Summary
-
$controller protected
Cake\Controller\Controller
Controller instance.
-
$error protected
Throwable
The exception being handled.
-
$exceptionHttpCodes protected
array<string, int>
Map of exceptions to http status codes.
-
$method protected
string
The method corresponding to the Exception this object is for.
-
$request protected
Cake\Http\ServerRequest|null
If set, this will be request used to create the controller that will render the error.
-
$template protected
string
Template to render for {@link \Cake\Core\Exception\CakeException}
Method Summary
-
__construct() public
Creates the controller to perform rendering on the error response.
-
__debugInfo() public
Returns an array that can be used to describe the internal state of this object.
-
_customMethod() protected
Render a custom error method/template.
-
_getController() protected
Get the controller instance to handle the exception. Override this method in subclasses to customize the controller used. This method returns the built in
ErrorController
normally, or if an error is repeated a bare controller will be used. -
_message() protected
Get error message.
-
_method() protected
Get method name
-
_outputMessage() protected
Generate the response using the controller object.
-
_outputMessageSafe() protected
A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.
-
_shutdown() protected
Run the shutdown events.
-
_template() protected
Get template for rendering exception info.
-
clearOutput() protected
Clear output buffers so error pages display properly.
-
getHttpCode() protected
Gets the appropriate http status code for exception.
-
render() public
Renders the response for the exception.
-
write() public
Emit the response content
Method Detail
__construct() ¶ public
__construct(Throwable $exception, Cake\Http\ServerRequest|null $request = null)
Creates the controller to perform rendering on the error response.
Parameters
-
Throwable
$exception Exception.
-
Cake\Http\ServerRequest|null
$request optional The request if this is set it will be used instead of creating a new one.
__debugInfo() ¶ public
__debugInfo(): array<string, mixed>
Returns an array that can be used to describe the internal state of this object.
Returns
array<string, mixed>
_customMethod() ¶ protected
_customMethod(string $method, Throwable $exception): Cake\Http\Response
Render a custom error method/template.
Parameters
-
string
$method The method name to invoke.
-
Throwable
$exception The exception to render.
Returns
Cake\Http\Response
_getController() ¶ protected
_getController(): Cake\Controller\Controller
Get the controller instance to handle the exception.
Override this method in subclasses to customize the controller used.
This method returns the built in ErrorController
normally, or if an error is repeated
a bare controller will be used.
Returns
Cake\Controller\Controller
_message() ¶ protected
_message(Throwable $exception, int $code): string
Get error message.
Parameters
-
Throwable
$exception Exception.
-
int
$code Error code.
Returns
string
_method() ¶ protected
_method(Throwable $exception): string
Get method name
Parameters
-
Throwable
$exception Exception instance.
Returns
string
_outputMessage() ¶ protected
_outputMessage(string $template): Cake\Http\Response
Generate the response using the controller object.
Parameters
-
string
$template The template to render.
Returns
Cake\Http\Response
_outputMessageSafe() ¶ protected
_outputMessageSafe(string $template): Cake\Http\Response
A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.
Parameters
-
string
$template The template to render.
Returns
Cake\Http\Response
_shutdown() ¶ protected
_shutdown(): Cake\Http\Response
Run the shutdown events.
Triggers the afterFilter and afterDispatch events.
Returns
Cake\Http\Response
_template() ¶ protected
_template(Throwable $exception, string $method, int $code): string
Get template for rendering exception info.
Parameters
-
Throwable
$exception Exception instance.
-
string
$method Method name.
-
int
$code Error code.
Returns
string
clearOutput() ¶ protected
clearOutput(): void
Clear output buffers so error pages display properly.
Returns
void
getHttpCode() ¶ protected
getHttpCode(Throwable $exception): int
Gets the appropriate http status code for exception.
Parameters
-
Throwable
$exception Exception.
Returns
int
render() ¶ public
render(): Cake\Http\Response
Renders the response for the exception.
Returns
Cake\Http\Response
write() ¶ public
write(Psr\Http\Message\ResponseInterface|string $output): void
Emit the response content
Parameters
-
Psr\Http\Message\ResponseInterface|string
$output The response to output.
Returns
void
Property Detail
$exceptionHttpCodes ¶ protected
Map of exceptions to http status codes.
This can be customized for users that don't want specific exceptions to throw 404 errors or want their application exceptions to be automatically converted.
Type
array<string, int>
$request ¶ protected
If set, this will be request used to create the controller that will render the error.
Type
Cake\Http\ServerRequest|null