I've previously had Whoops in 5.1 and 5.0; but since 5.2 the implementation I used earlier no longer works.
I have been unable to find a way to implement Whoops 2.0 to Laravel 5.2 as is.
Any suggestions?
I've previously had Whoops in 5.1 and 5.0; but since 5.2 the implementation I used earlier no longer works.
I have been unable to find a way to implement Whoops 2.0 to Laravel 5.2 as is.
Any suggestions?
只需将此方法添加到您的app/Exceptions/Handler.php
文件中,它会覆盖将生成 Symfony 错误响应的现有方法。如果应用程序处于配置模式,它将返回 Whoops 响应。如果您正在构建某种 API,您可能希望使用JsonResponseHandler
over ,PrettyPageHandler
这将为您提供一个很好的 JSON 异常响应。
/**
* Create a Symfony response for the given exception.
*
* @param \Exception $e
* @return mixed
*/
protected function convertExceptionToResponse(Exception $e)
{
if (config('app.debug')) {
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
return response()->make(
$whoops->handleException($e),
method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 500,
method_exists($e, 'getHeaders') ? $e->getHeaders() : []
);
}
return parent::convertExceptionToResponse($e);
}
Whoops 2.1 是 4 天前部署的。我刚刚尝试使用 Laravel 5.2,它工作得很好。
我刚刚按照 Matt Stauffer 的教程进行操作。
https://mattstauffer.co/blog/bringing-whoops-back-to-laravel-5