You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assign the callable used to handle the error. It can be a callable or a string with the format `Class::method`. The signature of the handler is the following:
72
-
73
-
```php
74
-
use Psr\Http\Message\ServerRequestInterface;
75
-
76
-
$handler = function (ServerRequestInterface $request) {
77
-
//Get the error info using the "error" attribute
78
-
$error = $request->getAttribute('error');
79
-
80
-
//Any output is captured and added to the body stream
81
-
echo $error->getMessage();
82
-
83
-
return (new Response())->withStatus($error->getCode());
If it's not provided, use [the default](src/ErrorHandlerDefault.php) that provides different outputs for different formats.
77
+
The request handler used to generate the response. If it's not provided, use [the default](src/ErrorHandlerDefault.php) that provides different outputs for different formats.
94
78
95
79
#### `catchExceptions(true)`
96
80
@@ -113,31 +97,6 @@ $dispatcher = new Dispatcher([
113
97
114
98
The attribute name used to store the instance of `Middlewares\HttpErrorException` with the error info in the server request. By default is `error`.
115
99
116
-
#### `arguments(...$args)`
117
-
118
-
Extra arguments to pass to the error handler. This is useful to inject, for example a logger:
119
-
120
-
```php
121
-
$handler = function (ServerRequestInterface $request, $logger) {
122
-
$error = $request->getAttribute('error');
123
-
$message = sprintf('Oops, a "%s" erro ocurried', $error->getCode());
124
-
125
-
//Log the error
126
-
$logger->error($message, $error->getContext());
127
-
128
-
//Build the response
129
-
$response = (new Response())->withStatus($error->getCode());
130
-
$response->getBody()->write($message);
131
-
132
-
return $response;
133
-
};
134
-
135
-
$dispatcher = new Dispatcher([
136
-
(new Middlewares\ErrorHandler($handler))
137
-
->arguments($logger)
138
-
]);
139
-
```
140
-
141
100
---
142
101
143
102
Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.
0 commit comments