修复ExceptionHandler中的错误处理,增加对json请求的支持
This commit is contained in:
parent
14ab4d734a
commit
03625cb601
@ -17,9 +17,14 @@ class ExceptionHandler extends Handler
|
|||||||
|
|
||||||
public function render(Request $request, Throwable $exception): Response
|
public function render(Request $request, Throwable $exception): Response
|
||||||
{
|
{
|
||||||
if ($exception instanceof Dumper) {
|
if ($exception instanceof Dumper) {
|
||||||
return \response(self::convertToHtml($exception));
|
return \response(self::convertToHtml($exception));
|
||||||
}
|
}
|
||||||
return parent::render($request, $exception);
|
// json请求返回json数据
|
||||||
|
if ($request->expectsJson()) {
|
||||||
|
return json(['code' => $exception->getCode() ?: 500, 'msg' => $exception->getMessage(), 'show' => 1]);
|
||||||
|
}
|
||||||
|
// 非json请求则返回一个页面
|
||||||
|
return new Response(200, [], $exception->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user