修复ExceptionHandler中的错误处理,增加对json请求的支持
This commit is contained in:
parent
14ab4d734a
commit
03625cb601
@ -20,6 +20,11 @@ class ExceptionHandler extends Handler
|
||||
if ($exception instanceof Dumper) {
|
||||
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