From 46247910a7b18ee3d6cff20b20fdded43bc03b27 Mon Sep 17 00:00:00 2001 From: Jens Segers Date: Sun, 23 Dec 2018 12:45:43 +0100 Subject: [PATCH] :memo: Add more information about error handlers --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7fe5b7d..2e35d15 100644 --- a/README.md +++ b/README.md @@ -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();