2016-01-21 92 views
1

我以前曾經在5.1和5.0中有過Whoops;但從5.2開始,我以前使用的實現不再有效。Laravel 5.2 +哎呦

我一直無法找到一種方法來實現Laravel 5.2的Whoops 2.0。

有什麼建議嗎?

+0

究竟什麼是行不通的?無法通過作曲家安裝,錯誤或什麼都不做? –

+0

https://github.com/GrahamCampbell/Laravel-Exceptions支持laravel 5.2 –

+0

@AmirBar我使用它,但它也做了很多其他的東西(即exceptionshandler),我不想或不需要。我只想要哎呀。 – FooBar

回答

4

只需將此方法添加到app/Exceptions/Handler.php文件中,它將覆蓋將生成Symfony錯誤響應的現有方法。如果應用程序處於配置模式,它將返回Whoops響應。如果您構建某種API,則可以改爲使用JsonResponseHandler而不是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); 
}