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]); } else if ($exception instanceof \Illuminate\Session\TokenMismatchException) { return redirect() ->back() ->withInput($request->except('password', 'password_confirmation', '_token')) ->with([ 'message' => ctrans('texts.token_expired'), 'message-type' => 'danger']); } return parent::render($request, $exception); } protected function unauthenticated($request, AuthenticationException $exception) { if ($request->expectsJson()) { return response()->json(['error' => 'Unauthenticated.'], 401); } $guard = Arr::get($exception->guards(), 0); switch ($guard) { case 'contact': $login = 'client.login'; break; case 'user': $login = 'login'; break; default: $login = 'default'; break; } return redirect()->guest(route($login)); } }