*/ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; protected $dontReport = [ AdminException::class, RuntimeException::class, ]; /** * Register the exception handling callbacks for the application. */ public function register(): void { $this->map(ModelNotFoundException::class, function (ModelNotFoundException $e) { $model = $e->getModel(); $resource = __($key = "model.{$model}"); if ($key === $resource) { $resource = class_basename($model); } return new HttpException(404, __(':resource not found', ['resource' => $resource]), $e); }); $this->renderable(function (RuntimeException $e, Request $request) { return response(['code' => $e->getCode(), 'message' => $e->getMessage()], $e->getHttpStatusCode()); }); $this->renderable(function (NotFoundHttpException $e, Request $request) { return response(['code' => Response::HTTP_NOT_FOUND, 'message' => $e->getMessage()], Response::HTTP_NOT_FOUND); }); $this->reportable(function (NoGatewayAvailableException $e) { foreach ($e->getExceptions() as $exception) { $this->report($exception); } return false; }); } protected function invalidJson($request, ValidationException $exception) { return response()->json([ 'code' => $exception->status, 'message' => $exception->getMessage(), 'errors' => $exception->errors(), ], $exception->status); } protected function unauthenticated($request, AuthenticationException $exception) { return $this->shouldReturnJson($request, $exception) ? response()->json(['code' => Response::HTTP_UNAUTHORIZED, 'message' => '请先登录'], 401) : redirect()->guest($exception->redirectTo() ?? url('/')); } }