woody / middleware-exception
遵循PSR-15规范的中间件,用于处理异常
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-09-11 14:53:38 UTC
README
此中间件可捕获深层中间件抛出的任何异常。
对于HttpException
,会创建一个包含其代码和消息的响应。对于任何其他异常,返回一个内部错误
。
实现
只需将中间件添加到您的dispatcher
管道的嵌套级别,以捕获最深中间件的任何异常。
// @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);