Exemple #1
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     } else {
         if ($e instanceof InvalidCredentialsException || $e instanceof NoAuthenticationException) {
             return $e->render();
         } else {
             if ($e instanceof TokenExpiredException) {
                 return response()->json(['error' => 'token_expired', 'error_description' => 'Your token has expired.'], $e->getStatusCode());
             } else {
                 if ($e instanceof TokenInvalidException) {
                     return response()->json(['error' => 'token_invalid', 'error_description' => 'The provided token was invalid.'], $e->getStatusCode());
                 } else {
                     if ($e instanceof JWTException) {
                         return response()->json(['error' => 'token_error', 'error_description' => 'There was an error generating or reading the access token. Please try again.'], $e->getStatusCode());
                     }
                 }
             }
         }
     }
     return parent::render($request, $e);
 }