正如文档中所述,您需要自定义render()的方法App\Exceptions\Handler。
编辑app/Exceptions/Handler.php:
public function render($request, Exception $e)
{
$error =$e->getMessage();
//do your stuff with the error message
return parent::render($request, $exception);
}
Run Code Online (Sandbox Code Playgroud)
要捕获所有错误并记录它们,您需要App\Exceptions\Handler像这样编辑文件
public function render($request, Exception $exception)
{
if ($exception){
// log the error
return response()->json([
'status' => $exception->getStatusCode(),
'error' => $exception->getMessage()
]);
}
return parent::render($request, $exception);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3805 次 |
| 最近记录: |