/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $exception * * @return \Illuminate\Http\Response */ public function render($request, Exception $exception) { if ($exception instanceof NotFoundHttpException && Request::acceptsHtml() && !Request::ajax() && !strrpos(Request::path(), '/assets/', -strlen(Request::path())) !== false) { return $this->handleNotFound(); } if ($exception instanceof AccessDeniedException || $exception instanceof InvalidRequestException) { return response()->json([], 401); } else { if ($exception instanceof FatalErrorException) { $message = $exception->getMessage(); if (App::environment() === 'production') { $message = 'An error occured'; } return response()->json(['error' => $message], 500); } } return parent::render($request, $exception); }