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(['error'=>'Record not found'],400); } 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)); } }