dtby67541 2018-06-22 02:37
浏览 55

lumen - handler.php不反映更新

I modified render method of Exceptions/Handler.php to return my own response instead of rendering lumen's error page when any errors occur.

Here is my render method updated.

/**
 * 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)
{
    // return parent::render($request, $e);
    return response()
                ->json([
                    'errors' => $e
                ]);
}

I expected it return my response when NotFoundHttpException happens, but lumen still shows its original error page...

I understand I should modify app/Exceptions/Handler.php, but because it doesn't work as I expect, I modified vendor/laravel/lumen/app/Exceptions/Handler.php instead. Here is the updated file.

/**
 * 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)
{
    return response(['test'=> 'test']);
    // return parent::render($request, $e);
}

It works as I expected (not showing error page but return json response).

In bootstrap/app.php, it seems correctly set to call App\Exceptions\Handler::class, not laravel\lumen\app\Exceptions\Handler::class.

/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

I've already tried reinstalling lumen and my docker environment. And I tried to modify Handler.php just after installing lumen (that is no other modification in app), but it doesn't work.

Anyone knows my changes are not reflected??

  • 写回答

1条回答 默认 最新

  • douzhao7445 2018-06-22 09:38
    关注

    I set a wrong value for bootstrap/app.php.

    I set like the below.

    require_once __DIR__.'/../../vendor/autoload.php';

    After I modified this part like following, lumen became to able to call Handler.php method.

    require_once __DIR__.'/../vendor/autoload.php';

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器