Skip to content

Commit

Permalink
📝 Add more information about error handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Dec 23, 2018
1 parent 3f2db58 commit 4624791
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,23 @@ Read more about service providers [here](https://container.thephpleague.com/3.x/

## Error Handlers

By default, Lean uses Slim's error handlers. If you want to overwrite error handler you can do that by simply adding your own error handler on the container like this:
By default, Lean uses Slim's error handlers. There are different ways to implement an error handler for Slim, read more about them [here](https://www.slimframework.com/docs/v3/handlers/error.html).

Typically you would create a custom error handler class that looks like this:

```php
class CustomErrorHandler
{
public function __invoke(ServerRequestInterface $request, Response $response, Throwable $exception)
{
return $response->withJson([
'error' => 'Something went wrong',
], 500);
}
}
```

Then you overwrite the default handler by adding it to the container:

```php
$app = new Jenssegers\Lean\App();
Expand Down

0 comments on commit 4624791

Please sign in to comment.