ExceptionRenderer
extends WebExceptionRenderer
in package
Backwards compatible Exception Renderer.
Use Cake\Error\Renderer\WebExceptionRenderer
instead.
Table of Contents
Properties
- $controller : Controller
- Controller instance.
- $error : Throwable
- The exception being handled.
- $exceptionHttpCodes : array<string, int>
- Map of exceptions to http status codes.
- $method : string
- The method corresponding to the Exception this object is for.
- $request : ServerRequest|null
- If set, this will be request used to create the controller that will render the error.
- $template : string
- Template to render for {@link \Cake\Core\Exception\CakeException}
Methods
- __construct() : mixed
- Creates the controller to perform rendering on the error response.
- __debugInfo() : array<string, mixed>
- Returns an array that can be used to describe the internal state of this object.
- render() : Response
- Renders the response for the exception.
- write() : void
- Emit the response content
- _customMethod() : Response
- Render a custom error method/template.
- _getController() : Controller
- Get the controller instance to handle the exception.
- _message() : string
- Get error message.
- _method() : string
- Get method name
- _outputMessage() : Response
- Generate the response using the controller object.
- _outputMessageSafe() : Response
- A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.
- _shutdown() : Response
- Run the shutdown events.
- _template() : string
- Get template for rendering exception info.
- clearOutput() : void
- Clear output buffers so error pages display properly.
- getHttpCode() : int
- Gets the appropriate http status code for exception.
Properties
$controller
Controller instance.
protected
Controller
$controller
$error
The exception being handled.
protected
Throwable
$error
$exceptionHttpCodes
Map of exceptions to http status codes.
protected
array<string, int>
$exceptionHttpCodes
= [
// Controller exceptions
\Cake\Controller\Exception\InvalidParameterException::class => 404,
\Cake\Controller\Exception\MissingActionException::class => 404,
// Datasource exceptions
\Cake\Datasource\Paging\Exception\PageOutOfBoundsException::class => 404,
\Cake\Datasource\Exception\RecordNotFoundException::class => 404,
// Http exceptions
\Cake\Http\Exception\MissingControllerException::class => 404,
// Routing exceptions
\Cake\Routing\Exception\MissingRouteException::class => 404,
]
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.
Tags
$method
The method corresponding to the Exception this object is for.
protected
string
$method
= ''
$request
If set, this will be request used to create the controller that will render the error.
protected
ServerRequest|null
$request
$template
Template to render for {@link \Cake\Core\Exception\CakeException}
protected
string
$template
= ''
Methods
__construct()
Creates the controller to perform rendering on the error response.
public
__construct(Throwable $exception[, ServerRequest|null $request = null ]) : mixed
Parameters
- $exception : Throwable
-
Exception.
- $request : ServerRequest|null = null
-
The request if this is set it will be used instead of creating a new one.
__debugInfo()
Returns an array that can be used to describe the internal state of this object.
public
__debugInfo() : array<string, mixed>
Return values
array<string, mixed>render()
Renders the response for the exception.
public
render() : Response
Return values
Response —The response to be sent.
write()
Emit the response content
public
write(ResponseInterface|string $output) : void
Parameters
- $output : ResponseInterface|string
-
The response to output.
_customMethod()
Render a custom error method/template.
protected
_customMethod(string $method, Throwable $exception) : Response
Parameters
- $method : string
-
The method name to invoke.
- $exception : Throwable
-
The exception to render.
Return values
Response —The response to send.
_getController()
Get the controller instance to handle the exception.
protected
_getController() : Controller
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.
Tags
Return values
Controller_message()
Get error message.
protected
_message(Throwable $exception, int $code) : string
Parameters
- $exception : Throwable
-
Exception.
- $code : int
-
Error code.
Return values
string —Error message
_method()
Get method name
protected
_method(Throwable $exception) : string
Parameters
- $exception : Throwable
-
Exception instance.
Return values
string_outputMessage()
Generate the response using the controller object.
protected
_outputMessage(string $template) : Response
Parameters
- $template : string
-
The template to render.
Return values
Response —A response object that can be sent.
_outputMessageSafe()
A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.
protected
_outputMessageSafe(string $template) : Response
Parameters
- $template : string
-
The template to render.
Return values
Response —A response object that can be sent.
_shutdown()
Run the shutdown events.
protected
_shutdown() : Response
Triggers the afterFilter and afterDispatch events.
Return values
Response —The response to serve.
_template()
Get template for rendering exception info.
protected
_template(Throwable $exception, string $method, int $code) : string
Parameters
- $exception : Throwable
-
Exception instance.
- $method : string
-
Method name.
- $code : int
-
Error code.
Return values
string —Template name
clearOutput()
Clear output buffers so error pages display properly.
protected
clearOutput() : void
getHttpCode()
Gets the appropriate http status code for exception.
protected
getHttpCode(Throwable $exception) : int
Parameters
- $exception : Throwable
-
Exception.
Return values
int —A valid HTTP status code.