bound('sentry') && $this->shouldReport($exception)) { app('sentry')->captureException($exception); } parent::report($exception); } /** * 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 ModelNotFoundException) { return response()->json(['message'=>'Record not found'],400); } else if($exception instanceof ThrottleRequestsException) { return response()->json(['message'=>'Too many requests'],429); } else if($exception instanceof FatalThrowableError) { return response()->json(['message'=>'Fatal error', 500]); } return parent::render($request, $exception); } protected function unauthenticated($request, AuthenticationException $exception) { if ($request->expectsJson()) { return response()->json(['error' => 'Unauthenticated.'], 401); } $guard = array_get($exception->guards(), 0); switch ($guard) { case 'contact': $login = 'contact.login'; break; case 'user': $login = 'login'; break; default: $login = 'default'; break; } return redirect()->guest(route($login)); } }