DefaultErrorHandler
in package
implements
ErrorHandlerInterface
A custom error handler class that implements the Slim `ErrorHandlerInterface`.
Handles various types of exceptions and generates appropriate error responses.
Tags
Interfaces, Classes, Traits and Enums
- ErrorHandlerInterface
Table of Contents
- __invoke() : ResponseInterface
- Handles the exception and returns a response with appropriate error details.
- getResponseWithCorsHeaders() : ResponseInterface
- Add CORS headers to the response and return a JSON response.
Methods
__invoke()
Handles the exception and returns a response with appropriate error details.
public
__invoke(ServerRequestInterface $request, Throwable $exception, bool $displayErrorDetails, bool $logErrors, bool $logErrorDetails) : ResponseInterface
Parameters
- $request : ServerRequestInterface
-
The PSR-7 request.
- $exception : Throwable
-
The caught exception.
- $displayErrorDetails : bool
-
Whether to display error details or not.
- $logErrors : bool
-
Whether to log errors or not.
- $logErrorDetails : bool
-
Whether to log error details or not.
Tags
Return values
ResponseInterface —The response with error details.
getResponseWithCorsHeaders()
Add CORS headers to the response and return a JSON response.
private
getResponseWithCorsHeaders(ServerRequestInterface $request, ResponseInterface $response, mixed $result, int $status_code) : ResponseInterface
Parameters
- $request : ServerRequestInterface
-
The PSR-7 request.
- $response : ResponseInterface
-
The PSR-7 response.
- $result : mixed
-
The response data.
- $status_code : int
-
The HTTP status code.
Return values
ResponseInterface —The response with CORS headers and JSON data.