当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpException::getResponse方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpKernel\Exception\HttpException::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpException::getResponse方法的具体用法?PHP HttpException::getResponse怎么用?PHP HttpException::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpKernel\Exception\HttpException的用法示例。


在下文中一共展示了HttpException::getResponse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 /**
  * 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);
     }
 }
开发者ID:webfactorybulgaria,项目名称:Base,代码行数:35,代码来源:Handler.php

示例2: render

 /**
  * 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);
 }
开发者ID:inad9300,项目名称:RESTyle,代码行数:54,代码来源:Handler.php

示例3: render

 /**
  * 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;
 }
开发者ID:jonathanpmartins,项目名称:lumen-framework,代码行数:25,代码来源:Handler.php

示例4: render

 /**
  * 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 = 'Unknown user';
     }
     $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('anthony.borrow@montserratretreat.org');
             $message->subject('Polanco Error @' . $fullurl . ' by: ' . $username . ' from: ' . $ip_address);
             $message->from('polanco@montserratretreat.org');
         });
         return view('errors.default');
     }
 }
开发者ID:arborrow,项目名称:montserrat,代码行数:45,代码来源:Handler.php

示例5: render

 /**
  * 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);
     }
 }
开发者ID:ziracmo,项目名称:Projet-transversal-2,代码行数:24,代码来源:Handler.php

示例6: renderException

 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);
 }
开发者ID:chatbox-inc,项目名称:lumen-providers,代码行数:15,代码来源:Middleware.php


注:本文中的Symfony\Component\HttpKernel\Exception\HttpException::getResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。