出于某种原因,我的Slim 4应用程序错误处理程序未捕获\Exception
可以捕获的错误,并且在浏览器中看到502 bad gateway
错误,这是我的ErrorMiddleware
配置(我正在使用PHP-DI进行配置):
$definitions[ErrorMiddleware::class] = static function(ContainerInterface $container): ErrorMiddleware {
$middleware = new ErrorMiddleware(
$container->get(CallableResolverInterface::class),
$container->get(ResponseFactoryInterface::class),
(bool)$container->get(Config::class)->get('main.debug'), //false or true
true,
true
);
$middleware->setErrorHandler(HttpNotFoundException::class, $container->get(NotFoundHandler::class));
return $middleware;
};
我试图添加处理程序来处理500个这样的
$middleware->setErrorHandler(HttpInternalServerErrorException::class, $container->get(NotFoundHandler::class) );
错误但是它不起作用,直到我将所有 Controller Action 都用
502 bad gateway
包围为止,我仍然看到try/catch(\Exception $e)
。我是否需要添加其他错误处理程序?我还不清楚如何在Slim 4应用程序中正确设置处理。
更新:我发现默认情况下, slim
ErrorMiddleware
捕获了扩展HttpException
的 slim Exception
,但是为什么不直接使用Exception
甚至Throwable
来优雅地退出具有错误页面的应用程序
最佳答案
好的,这对我来说是不好的,而且还算是 slim ,因为ErrorMiddlware
已配置为记录错误,所以它无法执行'log_error()'功能,但是我尚未安装和配置Monolog
,因此将日志写入php-fpm
日志中, nginx
并引发502错误
关于php - Slim 4错误处理未捕获基本异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59334307/