【发布时间】:2017-01-18 11:20:02
【问题描述】:
我有一个 silex 应用程序。我有一个注册的通用处理程序:
$app->error(function (\Exception $e) use ($app) {
return (new JsonResponse(['message' => 'Something truly horrible happened. Sorry.', 500)])->send();
}
);
然而,当 $app::share() 中出现异常时,它不会触发:
$app->share(function () {
throw new \Exception('wtf');
}));
这个异常不会被错误处理程序处理,而是直接弹出,就好像根本没有处理程序一样:
exception 'Exception' with message 'wtf' in appinit.php:230
Stack trace: #0 ./vendor/pimple/pimple/lib/Pimple.php(126): Closure$#12() #1 ./vendor/pimple/pimple/lib/Pimple.php(83): Closure$Pimple::share() #2 ./web/appinit.php(234): Pimple->offsetGet() #3 app.php(6): include() #4 {main}
我只是期望一个带有内容的基本 400 Bad Request 响应:
{
"message": "Something truly horrible happened. Sorry.",
}
为什么我的处理程序没有激活?
【问题讨论】:
-
我认为这与您发布的问题无关。您是否使用 (
$app['debug'] = true) 上的运行标志运行此代码?如果是这样,你能把它关掉看看会发生什么吗?