求助,Laravel 重新接管 dingoApi 错误
因为在项目上线后要屏蔽sql方面的报错,所有按网上教的我让laravel重新接管的错误处理
我在app/Providers/AppServiceProvider
的boot
方法里加上了
// 将所有的 Exception 全部交给 App\Exceptions\Handler 来处理\
app('api.exception')->register(function (\Exception $exception) {\
$request = Request::capture();\
return app('App\Exceptions\Handler')->render($request, $exception);\
});
然后修改 app/Exceptions/Handle
中的 render
方法
public function render($request, Exception $exception)\
{
$class = get_class($exception);
if ((!env('API_DEBUG'))
&& in_array($class, self::SHIELD_ERR)) {
return [
'status_code' => 500,
'message' => '服务异常',
'data' => []
];
}
}
// 屏蔽报错列表\
const SHIELD_ERR = [
'Illuminate\Database\QueryException'
];
上线后再日志里看到这个报错
Call to a member function send() on null {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function send() on null at /www/wwwroot/MeijietuWebApi/public/index.php:58)
[stacktrace]
#0 {main}
"}
Uncaught Error: Call to a member function send() on null
in /www/wwwroot/MeijietuWebApi/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 /www/wwwroot/MeijietuWebApi/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(89): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#2 {main}
thrown {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 1): Uncaught Error: Call to a member function send() on null in /www/wwwroot/MeijietuWebApi/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 /www/wwwroot/MeijietuWebApi/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(89): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->renderHttpResponse(Object(Symfony\\Component\\Debug\\Exception\\FatalThrowableError))
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleException(Object(Symfony\\Component\\Debug\\Exception\\FatalThrowableError))
#2 {main}
thrown at /www/wwwroot/MeijietuWebApi/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112)
[stacktrace]
#0 {main}
"}
目前没发现会有什么影响,但还是想修好,就是看不懂
本作品采用《CC 协议》,转载必须注明作者和本文链接