码迷,mamicode.com
首页 > 其他好文 > 详细

Bringing Whoops Back to Laravel 5

时间:2015-03-12 09:48:17      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

You might be missing the "prettier" Whoops error handler from Laravel 4. If so, here‘s how to bring it back.

First, composer require filp/whoops:~1.0.

Then open app/Exceptions/Handler.php, and in the render() method, add a Whoops handler in the else condition. Maybe something like this:

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
        if ($this->isHttpException($e))
        {
            return $this->renderHttpException($e);
        }


        if (config(‘app.debug‘))
        {
            return $this->renderExceptionWithWhoops($e);
        }

        return parent::render($request, $e);
    }

    /**
     * Render an exception using Whoops.
     * 
     * @param  \Exception $e
     * @return \Illuminate\Http\Response
     */
    protected function renderExceptionWithWhoops(Exception $e)
    {
        $whoops = new \Whoops\Run;
        $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());

        return new \Illuminate\Http\Response(
            $whoops->handleException($e),
            $e->getStatusCode(),
            $e->getHeaders()
        );
    }

That‘s it!

Thanks to this thread on the Laracasts forum for getting me moving in the right direction.

 

参考地址:https://laracasts.com/discuss/channels/general-discussion/whoops-removed-from-laravel-5

原文地址:https://mattstauffer.co/blog/bringing-whoops-back-to-laravel-5

Bringing Whoops Back to Laravel 5

标签:

原文地址:http://www.cnblogs.com/leonkao/p/4331492.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!