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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助