Ejemplo n.º 1
0
 /**
  * Response for NotFoundHttpException (Route was not found).
  *
  * @param NotFoundHttpException $exception
  *
  * @return JsonResponse
  */
 private function responseHttpException(HttpExceptionInterface $exception)
 {
     return $this->createResponse($exception->getStatusCode(), $exception->getMessage(), $exception->getHeaders());
 }
Ejemplo n.º 2
0
 /**
  * Get the error view.
  *
  * @param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $exception
  * @return \Illuminate\View\View|null
  */
 protected function getErrorView(HttpExceptionInterface $exception)
 {
     $view = $this->app['view'];
     $statuses = [$exception->getStatusCode()];
     if (!env('APP_DEBUG', false)) {
         $statuses[] = 500;
     }
     foreach (array_unique($statuses) as $status) {
         if ($view->exists($file = "error.{$status}")) {
             return $view->make($file, compact('status', 'exception'));
         }
     }
     return null;
 }
Ejemplo n.º 3
0
 /**
  * Prepares parameters for HttpExceptionInterface
  *
  * @param HttpExceptionInterface $exception
  */
 protected function prepareHttpException(HttpExceptionInterface $exception)
 {
     $this->sendHttpCode($exception->getStatusCode());
     $this->headers($exception->getHeaders());
 }
Ejemplo n.º 4
0
 /**
  * Create a new response from an exception.
  *
  * @param  Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $exception
  * @return \Peakfijn\GetSomeRest\Http\Response
  */
 public static function makeFromException(HttpExceptionInterface $exception)
 {
     $response = new static($exception instanceof RestException ? $exception->getContent() : $exception->getMessage(), $exception->getStatusCode(), $exception->getHeaders());
     $response->setException($exception);
     return $response;
 }
Ejemplo n.º 5
0
 /**
  * Return a new JSON response from a HttpException
  *
  * @param  HttpExceptionInterface $httpException
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function withHttpException(HttpExceptionInterface $httpException)
 {
     $response = new JsonResponse([], $httpException->getStatusCode());
     $statusText = JsonResponse::$statusTexts[$httpException->getStatusCode()];
     $data = array("errors" => array(array('code' => $this->getErrorCode($httpException->getStatusCode()), 'status' => $httpException->getStatusCode(), 'detail' => $httpException->getMessage() ?: $statusText)));
     $response->setData($data);
     return $response;
 }