Beispiel #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 this exception is listed for code forwarding
     if ($this->shouldConvertToHttpException($e)) {
         $e = new HttpException($e->getCode(), $e->getMessage(), $e);
     }
     // If the request wants JSON (AJAX doesn't always want JSON)
     if ($request->wantsJson()) {
         // Define the response
         $response = ['errors' => 'Sorry, something went wrong.'];
         // If the app is in debug mode
         if (config('app.debug')) {
             // Add the exception class name, message and stack trace to response
             $response['exception'] = get_class($e);
             // Reflection might be better here
             $response['message'] = $e->getMessage();
             $response['trace'] = $e->getTrace();
         }
         // Default response of 400
         $status = 400;
         // If this exception is an instance of HttpException
         if ($this->isHttpException($e)) {
             // Grab the HTTP status code from the Exception
             $status = $e->getStatusCode();
         }
         // Return a JSON response with the response array and status code
         unset($response['trace']);
         return response()->json($response, $status);
     }
     // Default to the parent class' implementation of handler
     return parent::render($request, $e);
 }
Beispiel #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)
 {
     /*
      * Notification on TokenMismatchException
      */
     if ($e instanceof TokenMismatchException) {
         Notification::error(trans('global.Security token expired. Please, repeat your request.'));
         return redirect()->back()->withInput();
     }
     if ($e instanceof HttpResponseException) {
         return $e->getResponse();
     } elseif ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     } elseif ($e instanceof AuthorizationException) {
         $e = new HttpException(403, $e->getMessage());
     } elseif ($e instanceof ValidationException && $e->getResponse()) {
         return $e->getResponse();
     }
     if ($this->isHttpException($e)) {
         return $this->toIlluminateResponse($this->renderHttpException($e), $e);
     } else {
         // Custom error 500 view on production
         if (app()->environment() == 'production') {
             return response()->view('errors.500', [], 500);
         }
         return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
     }
 }
Beispiel #3
0
 /**
  * Render the given HttpException.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     // load base JS
     JavaScript::put(['base_url' => url('/'), 'site_name' => config('settings.app_name_' . config('app.locale'))]);
     $seo_meta = ['page_title' => 'Erreur ' . $e->getStatusCode(), 'meta_desc' => $e->getMessage(), 'meta_keywords' => ''];
     $data = ['code' => $e->getStatusCode(), 'seo_meta' => $seo_meta, 'css' => elixir('css/app.error.css')];
     return response()->view('templates.common.errors.errors', $data);
 }
Beispiel #4
0
 /**
  * Render the given HttpException.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     if (view()->exists('errors.' . $e->getStatusCode())) {
         return response()->view('errors.' . $e->getStatusCode(), [], $e->getStatusCode());
     } else {
         return (new SymfonyDisplayer(config('app.debug')))->createResponse($e);
     }
 }
 function it_prepares_http_exceptions(HttpException $httpException)
 {
     $httpException->getStatusCode()->willReturn(404);
     $httpException->getHeaders()->willReturn(['Header:test']);
     $this->handleException($httpException);
     $this->sendHttpCode()->shouldReturn(404);
     $this->headers()->shouldReturn(['Header:test']);
 }
Beispiel #6
0
 /**
  * Render the given HttpException.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view()->exists("errors.{$status}")) {
         return response()->view("errors.{$status}", ['message' => $e->getMessage()], $status);
     }
     return parent::renderHttpException($e);
 }
 protected function convertHttpExceptionToJsonResponse(HttpException $exc)
 {
     $data = json_decode($exc->getMessage(), true);
     if (!is_array($data)) {
         $data = ['_message' => $exc->getMessage()];
     }
     return new JsonResponse($data, $exc->getStatusCode());
 }
Beispiel #8
0
 /**
  * Render the given HttpException.
  *
  * @param HttpException $e
  *
  * @return \Illuminate\Http\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $code = $e->getStatusCode();
     $default_config = ['title' => 'エラーが発生しました。', 'msg' => 'エラーが発生しました。'];
     $error_set = config("errors.{$code}", $default_config);
     $data = array_merge($error_set, ['exception' => $e]);
     return response()->view('errors.all', $data, $code);
 }
 /**
  * Render the given HttpException.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view()->exists(config('smile.theme') . '::' . "errors.{$status}")) {
         return response()->view(config('smile.theme') . '::' . "errors.{$status}", [], $status);
     }
     return (new SymfonyDisplayer(config('app.debug')))->createResponse($e);
 }
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view()->exists($this->pathErrors . $status)) {
         return response()->view($this->pathErrors . $status, ['exception' => $e], $status, $e->getHeaders());
     } else {
         return parent::renderHttpException($e);
     }
 }
 /**
  * Render the given HttpException.
  *
  * @param  HttpException $e
  * @return Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view()->exists("errors.{$status}")) {
         return response(view("errors.{$status}"), $status);
     } else {
         return (new SymfonyExceptionHandler(env('APP_DEBUG')))->createResponse($e);
     }
 }
Beispiel #12
0
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view()->exists("errors.{$status}")) {
         return response()->view("errors.{$status}", [], $status);
     } else {
         return response()->view("errors.default", [], $status);
     }
 }
 /**
  * Render the given HttpException.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view()->exists("jplatformui::errors.{$status}")) {
         return response()->view("jplatformui::errors.{$status}", ['exception' => $e], $status);
     } else {
         return $this->convertExceptionToResponse($e);
     }
 }
Beispiel #14
0
 /**
  * Render the given HttpException.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException $e
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view()->exists("soda-example::errors.{$status}")) {
         return response()->view("soda-example::errors.{$status}", ['exception' => $e], $status, $e->getHeaders());
     } else {
         return response()->view("soda-example::errors.other", ['exception' => $e], $status, $e->getHeaders());
     }
 }
Beispiel #15
0
 /**
  * Render a HTTP exception, including a custom error message.
  *
  * @param  \HttpException  $e
  * @return \Illuminate\Http\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (!config('app.debug') && view()->exists("errors.{$status}")) {
         return response()->view("errors.{$status}", compact('e'), $status);
     } else {
         return (new SymfonyDisplayer(config('app.debug')))->createResponse($e);
     }
 }
Beispiel #16
0
 /**
  * Функция для отображения сообщений на страницах ошибок (404, 500 etc.)
  * @param HttpException $e
  * @return \Illuminate\Http\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view()->exists("errors.{$status}")) {
         return response()->view("errors.{$status}", ['message' => $e->getMessage(), 'status' => $status, 'headers' => $e->getHeaders()], $status);
     } else {
         return $status;
     }
 }
 /**
  * Render the given HttpException.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (!config('app.debug') && view()->exists("streams::errors.{$status}")) {
         return response()->view("streams::errors.{$status}", ['message' => $e->getMessage()], $status);
     } else {
         return (new SymfonyDisplayer(config('app.debug')))->handle($e);
     }
 }
Beispiel #18
0
 /**
  * 自定义错误,如果view/errors/ 下存在错误模板,就显示错误模板。
  * @param $request
  * @param HttpException $e
  * @return \Laravel\Lumen\Http\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException($request, HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view()->exists("errors.{$status}")) {
         return response(view("errors.{$status}", []), $status);
     } else {
         return parent::render($request, $e);
     }
 }
Beispiel #19
0
 /**
  * 自定义错误页
  */
 protected function renderHttpException(HttpException $e)
 {
     if (Request::ajax() and !config('app.debug')) {
         return responseJson($e->getStatusCode(), false);
     } elseif (view()->exists('error.common') and !config('app.debug')) {
         return response()->view('error.common', ['errorCode' => $e->getStatusCode()], $e->getStatusCode());
     } else {
         return (new SymfonyDisplayer(config('app.debug')))->createResponse($e);
     }
 }
Beispiel #20
0
 /**
  * Render the given HttpException.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     $view = $e->context !== Application::CXT_SITE ? "cms::errors." . $status : "errors." . $status;
     if (view()->exists($view)) {
         return response()->view($view, ['exception' => $e], $status);
     } else {
         return $this->convertExceptionToResponse($e);
     }
 }
Beispiel #21
0
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view_exists("errors.{$status}")) {
         $viewData = ['app_env' => env('APP_ENV'), 'app_version' => config('app.version'), 'app_title' => config('app.title'), 'site_name' => config('app.site_name'), 'scripts' => ['jquery.js', 'jquery-ui.min.js', 'foundation.min.js', 'tag-it.min.js', 'app.js'], 'modules' => \Module::slugs(), 'exception' => $e];
         return response()->view("errors.{$status}", $viewData, $status);
     } else {
         return $this->convertExceptionToResponse($e);
     }
 }
Beispiel #22
0
 /**
  * Render the given HttpException.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     $env = \App::environment();
     if (view()->exists("errors.{$status}") && $env != KACANA_ENVIRONMENT_DEVELOPMENT) {
         return response()->view("errors.{$status}", [], $status);
     } else {
         return (new SymfonyDisplayer(config('app.debug')))->createResponse($e);
     }
 }
Beispiel #23
0
 /**
  * Render the given HttpException.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderHttpException(HttpException $e)
 {
     $status = $e->getStatusCode();
     if (view()->exists("public::errors.{$status}")) {
         $theme = Theme::uses('public')->layout('error');
         return $theme->of("public::errors.{$status}", ['exception' => $e])->render();
     } else {
         return $this->convertExceptionToResponse($e);
     }
 }
 /**
  * Handle not found exception.
  *
  * @param  \Symfony\Component\HttpKernel\Exception\HttpException $e
  *
  * @return mixed
  */
 public function handle(HttpException $e)
 {
     $errorViewName = 'errors.' . $e->getStatusCode();
     // Here we check whether view is exist. For example if you got 404 status,
     // then we need a `errors.404` view file. If it exists, we render that view,
     // otherwise, we just throw back the exception, leaving it uncaught.
     if (View::exists($errorViewName)) {
         return Response::make(View::make($errorViewName, ['error' => $e]), $e->getStatusCode())->send();
     }
     throw $e;
 }
 /**
  * Create a new rate limit exceeded exception instance.
  *
  * @param string     $message
  * @param \Exception $previous
  * @param array      $headers
  * @param int        $code
  *
  * @return void
  */
 public function __construct($message = null, Exception $previous = null, $headers = [], $code = 0)
 {
     if (array_key_exists('X-RateLimit-Reset', $headers)) {
         $headers['Retry-After'] = $headers['X-RateLimit-Reset'] - time();
     }
     parent::__construct(429, $message ?: 'You have exceeded your rate limit.', $previous, $headers, $code);
 }
 /**
  * Constructor.
  *
  * @param string     $message  The internal exception message
  * @param \Exception $previous The previous exception
  * @param int        $code     The internal exception code
  */
 public function __construct($message = null, \Exception $previous = null, $code = 0)
 {
     if (!$message) {
         $message = \Lang::get('api-proxy-laravel::messages.proxy_cookie_invalid');
     }
     parent::__construct(500, $message, $previous, array(), $code);
 }
 public function __construct(ApiProblem $apiProblem, \Exception $previous = null, array $headers = array(), $code = 0)
 {
     $this->apiProblem = $apiProblem;
     $statusCode = $apiProblem->getStatusCode();
     $message = $apiProblem->getTitle();
     parent::__construct($statusCode, $message, $previous, $headers, $code);
 }
Beispiel #28
0
 public function __construct($message = null)
 {
     if (!$message) {
         $message = $this->generic;
     }
     parent::__construct(500, $message);
 }
 /**
  * @param string $message
  * @param int $code
  * @param \Exception $previous
  */
 public function __construct($message = null, $code = 0, \Exception $previous = null)
 {
     /*
      * @see https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
      */
     parent::__construct(599, $message, $previous, array(), $code);
 }
Beispiel #30
0
 /**
  * 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)
 {
     /* TODO: criar página de 404 generica */
     if ($exception instanceof ModelNotFoundException) {
         $exception = new HttpException($exception->getMessage(), $exception);
     }
     if ($exception instanceof TokenMismatchException) {
         Flash::error('Sua sessão expirou.\\n Atualize a página usando o Ctrl+F5 e tente novamente.');
         return redirect()->back()->withInput($request->except('password'));
     }
     #if ($exception instanceof AdmixException) {
     #    Flash::error($exception->getMessage());
     #    return redirect()
     #        ->back();
     #}
     return parent::render($request, $exception);
 }