/**
  * 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 \Tymon\JWTAuth\Exceptions\TokenExpiredException) {
             return response()->json(['errors' => ['The access token is expired.']], $e->getStatusCode());
         } else {
             if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) {
                 return response()->json(['errors' => ['The access token is invalid.']], $e->getStatusCode());
             } else {
                 if ($e instanceof \Tymon\JWTAuth\Exceptions\JWTException) {
                     return response()->json(['errors' => ['The internal server error is occured.']], $e->getStatusCode());
                 } else {
                     if ($e instanceof NotFoundHttpException) {
                         return response()->json(['errors' => ['The resource hasn\'t found.']], $e->getStatusCode());
                     } else {
                         if ($e instanceof MethodNotAllowedHttpException) {
                             return response()->json(['errors' => ['The method doesn\'t allowed for this resource.']], $e->getStatusCode());
                         }
                     }
                 }
             }
         }
     }
     return parent::render($request, $e);
 }
예제 #2
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);
     }
     if ($e instanceof TokenExpiredException) {
         return response()->json(['token_expired'], $e->getStatusCode());
     }
     if ($e instanceof TokenInvalidException) {
         return response()->json(['token_invalid'], $e->getStatusCode());
     }
     return parent::render($request, $e);
 }
예제 #3
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);
     }
     /**
      * Response Exception as Json
      *
      */
     if ($request->wantsJson()) {
         $error = new \stdclass();
         $error->error = true;
         if ($e instanceof NotFoundHttpException) {
             $error->code = $e->getStatusCode();
         } else {
             $error->code = $e->getCode();
         }
         if ($error->code == 0) {
             $error->code = 400;
         }
         if ($e instanceof ValidatorException) {
             $error->message = $e->getMessageBag();
         } else {
             $error->message = $e->getMessage();
             if (\App::environment('local')) {
                 $error->file = $e->getFile();
                 $error->line = $e->getLine();
             }
         }
         return response()->json($error, $error->code);
     }
     return parent::render($request, $e);
 }
예제 #4
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);
     }
     if ($e->getStatusCode() == '404') {
         return redirect('/');
     }
     return parent::render($request, $e);
 }
예제 #5
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 TokenExpiredException) {
             return response()->json(['token_expired'], $e->getStatusCode());
         } else {
             if ($e instanceof TokenInvalidException) {
                 return response()->json(['token_invalid'], $e->getStatusCode());
             } else {
                 if ($e->getMessage() === 'The token could not be parsed from the request') {
                     return response()->json(['token_invalid'], 400);
                 }
             }
         }
     }
     return parent::render($request, $e);
 }
예제 #6
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);
     } elseif ($e instanceof HttpException && \App::isLocal() === false) {
         Response::json(['result' => false, 'message' => $e->getMessage()])->setStatusCode($e->getStatusCode())->send();
         exit;
     }
     return parent::render($request, $e);
 }
예제 #7
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);
     }
     if ($request->isMethod('get')) {
         if ($e->getStatusCode() == 404) {
             return response()->view('index');
         }
     }
     return parent::render($request, $e);
 }
예제 #8
0
파일: Handler.php 프로젝트: chictem/chictem
 /**
  * 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);
     }
     $space = $this->getViewSpace($request);
     $status = $e->getStatusCode();
     if (view()->exists($space . '.errors.' . $status)) {
         return response()->view($space . '.errors.' . $status, compact('e'), $status);
     }
     return parent::render($request, $e);
 }
예제 #9
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);
 }
예제 #10
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);
     }
     if ($e instanceof HttpException) {
         // HTTP Exception detected, render custom error view
         $statuscode = $e->getStatusCode();
         $viewpath = "clearboard.pages.errors.{$statuscode}";
         if (view()->exists($viewpath)) {
             return response()->view($viewpath);
         }
     }
     return parent::render($request, $e);
 }
예제 #11
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);
     }
     if ($e instanceof HttpException) {
         $errorData = ["message" => $e->getMessage(), "httpCode" => $e->getStatusCode(), "code" => $e->getCode()];
         if ($request->ajax()) {
             return response()->json($errorData, $errorData['httpCode']);
         } else {
             return response()->view('errors.phylab', $errorData, $errorData['httpCode']);
         }
     }
     return parent::render($request, $e);
 }
 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $route = $request->attributes->get('_route');
     if (empty($route)) {
         $route = $request->attributes->get('_master_request_route');
     }
     if (!$this->provider->isItemWhitelisted($route)) {
         $notFoundException = new NotFoundHttpException('Sorry, the page that you requested was not found.');
         $statusCode = $notFoundException->getStatusCode();
         $parameters = ['status_code' => $statusCode, 'status_text' => Response::$statusTexts[$statusCode], 'currentContent' => '', 'exception' => FlattenException::create($notFoundException), 'logger' => $this->logger];
         $view = View::create($parameters);
         $view->setFormat(self::VIEW_FORMAT);
         $view->setTemplate($this->findTemplate($request, $statusCode, $this->kernel->isDebug()));
         $response = $this->viewHandler->handle($view);
         $event->setResponse($response);
     }
 }
예제 #13
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 ($request->segment(1) == 'api' || $request->ajax()) {
         if ($this->isHttpException($e)) {
             $message = 'Http exception occurred';
             switch ($e->getStatusCode()) {
                 case 404:
                     $message = 'Method not found';
                     break;
                 case 405:
                     $message = 'Method not allowed';
                     break;
                 case 401:
                     $message = 'Unauthorized';
                     break;
                 case 501:
                     $message = 'Maintenance';
                     break;
             }
             return response()->json(['request_id' => uniqid(), 'status' => 'failure', 'message' => $message, 'timestamp' => Carbon::now()], $e->getStatusCode());
         } else {
             if ($e instanceof ModelNotFoundException) {
                 $e = new NotFoundHttpException($e->getMessage(), $e);
                 return response()->json(['request_id' => uniqid(), 'status' => 'not found', 'message' => $e->getMessage(), 'timestamp' => Carbon::now()], $e->getStatusCode());
             }
         }
     }
     if (!config('app.debug', false) && !$this->isHttpException($e)) {
         switch ($e->getStatusCode()) {
             case 500:
                 if ($request->segment(1) == 'api' || $request->ajax()) {
                     return response()->json(['request_id' => uniqid(), 'status' => 'failure', 'message' => 'Internal server error', 'timestamp' => Carbon::now()], 500);
                 }
                 return response()->view('errors.500', ['exception' => $e], 500);
                 break;
             case 405:
                 return response()->view('errors.500', ['exception' => $e], 405);
                 break;
         }
     }
     return parent::render($request, $e);
 }
예제 #14
-12
 /**
  * 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);
     }
     if ($request->acceptsJson() && $request->ajax()) {
         // Provide JSON response
         $response = ['success' => false, 'error' => ''];
         // Set response HTTP code and headers
         if ($e instanceof HttpExceptionInterface) {
             $code = $e->getStatusCode();
             $headers = $e->getHeaders();
         } else {
             $code = 500;
             $headers = [];
         }
         if ($e instanceof MaxUploadSizeException) {
             $response['error'] = 'File too big.';
         } elseif ($e instanceof DisallowedFileTypeException) {
             $response['error'] = 'Disallowed file type.';
         } else {
             $response['error'] = 'Server error.';
         }
         // Add exception to response if debug mode is turned on
         if (config('app.debug') === true) {
             $response['exception'] = ['exception' => get_class($e), 'code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTrace(), 'file' => $e->getFile(), 'file_line' => $e->getLine()];
         }
         return response()->json($response, $code, $headers);
     } else {
         // Normal HTML error page
         return parent::render($request, $e);
     }
 }