woody / middleware-exception
Middleware PSR-15 compliant which handle Exceptions
dev-master
2019-01-10 22:51 UTC
Requires
- php: ^7.1
- woody/http-server-middleware: dev-master
This package is auto-updated.
Last update: 2024-12-11 15:44:07 UTC
README
This middleware catch any exception thrown by deeper middleware.
For HttpException
, a response with its code and message is created.
For any other exception, an Internal Error
is returned.
Implementation
Just add the middleware into your dispatcher
pipeline at a nested level to catch any exception of deepest middleware.
// @todo: generate request $dispatcher = new Dispatcher(); $dispatcher->pipe(new CorrelationIdMiddleware()); $dispatcher->pipe(new ExceptionMiddleware()); $dispatcher->pipe(new MyAddMiddleware()); // @todo: add other middleware $response = $dispatcher->handle($request);