Exemplo n.º 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)
 {
     /*
      * 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);
     }
 }
Exemplo n.º 2
0
 /**
  * Render an exception into an HTTP response. Should conform to RFC "Problem Details for HTTP APIs":
  * https://tools.ietf.org/html/rfc7807
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof HttpResponseException) {
         // return $e->getResponse();
         $title = 'An exception happened when preparing the HTTP response';
     } elseif ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
         $statusCode = HttpStatus::NotFound;
         $title = 'The entity does not exist';
     } elseif ($e instanceof AuthorizationException) {
         $e = new HttpException(HttpStatus::Forbidden, $e->getMessage());
         $title = 'You are not authorized to access this information';
     } elseif ($e instanceof ValidationException && $e->getResponse()) {
         $errors = json_decode($e->getResponse()->content());
         $statusCode = HttpStatus::UnprocessableEntity;
         $title = 'Data validation error';
     }
     $response = [];
     /* $response = [
            'type' => '',
            'title' => 'Something went wrong',
            'detail' => $e->getMessage() ?: 'No more information is known',
            'instance' => ''
        ]; */
     if (isset($title)) {
         $response['title'] = $title;
     }
     if ($e->getMessage()) {
         $response['detail'] = $e->getMessage();
     }
     if (isset($errors)) {
         $response['invalid-fields'] = $errors;
     }
     if (env('APP_DEBUG', false)) {
         $response['debug'] = ['exception' => get_class($e), 'trace' => $e->getTrace(), 'response' => method_exists($e, 'getResponse') ? $e->getResponse() : ''];
     }
     if (!isset($statusCode)) {
         if (method_exists($e, 'getStatusCode')) {
             $statusCode = $e->getStatusCode();
         } else {
             $statusCode = HttpStatus::InternalServerError;
         }
     }
     return response()->json($response, $statusCode);
     // return parent::render($request, $e);
 }
Exemplo n.º 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 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();
     }
     $fe = FlattenException::create($e);
     $handler = new SymfonyExceptionHandler(env('APP_DEBUG', false));
     $decorated = $this->decorate($handler->getContent($fe), $handler->getStylesheet($fe));
     $response = new Response($decorated, $fe->getStatusCode(), $fe->getHeaders());
     $response->exception = $e;
     return $response;
 }
Exemplo n.º 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)
 {
     $fullurl = $request->fullUrl();
     if (isset(Auth::User()->name)) {
         $username = Auth::User()->name;
     } else {
         $username = '******';
     }
     $ip_address = 'Unspecified IP Address';
     if (!empty($request->ip())) {
         $ip_address = $request->ip();
     }
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     if ($e instanceof HttpResponseException) {
         return $e->getResponse();
     } elseif ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     } elseif ($e instanceof AuthenticationException) {
         return $this->unauthenticated($request, $e);
     } elseif ($e instanceof AuthorizationException) {
         $e = new HttpException(403, $e->getMessage());
     } elseif ($e instanceof ValidationException && $e->getResponse()) {
         return $e->getResponse();
     }
     $e->debug = TRUE;
     if ($this->isHttpException($e)) {
         return $this->toIlluminateResponse($this->renderHttpException($e), $e);
     } else {
         Mail::send('emails.error', ['error' => $this->convertExceptionToResponse($e)], function ($message) use($fullurl, $username, $ip_address) {
             $message->to('*****@*****.**');
             $message->subject('Polanco Error @' . $fullurl . ' by: ' . $username . ' from: ' . $ip_address);
             $message->from('*****@*****.**');
         });
         return view('errors.default');
     }
 }
Exemplo n.º 5
0
 /**
  * Render an exception into a response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     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 {
         return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
     }
 }
Exemplo n.º 6
0
 protected function renderException($request, $e)
 {
     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();
     }
     $fe = FlattenException::create($e);
     $data = env("APP_DEBUG", false) ? $fe->toArray() : ["message" => "whoops, something wrong."];
     return $this->response()->error($data);
 }