예제 #1
0
 /**
  * Transform the provided exception.
  *
  * @param \Exception $exception
  *
  * @return \Exception
  */
 public function transform(Exception $exception)
 {
     if ($exception instanceof ExceptionInterface) {
         $exception = new BadRequestHttpException($exception->getMessage());
     }
     return $exception;
 }
예제 #2
0
 /**
  * Transform the provided exception.
  *
  * @param \Exception $exception
  *
  * @return \Exception
  */
 public function transform(Exception $exception)
 {
     if ($exception instanceof ExceptionInterface) {
         $exception = new BadRequestHttpException($exception->getMessage());
     } elseif ($exception instanceof ModelNotFoundException) {
         $exception = new NotFoundHttpException('Resource not found.');
     }
     return $exception;
 }
예제 #3
0
 /**
  * @param BadRequestHttpException $exception
  *
  * @return Response
  *
  * @throws BadRequestHttpException
  */
 public function createBadRequestResponse(BadRequestHttpException $exception)
 {
     $body = array('success' => false);
     if ($exception instanceof ValidationExceptionSet) {
         $body['error']['global'] = 'You have validation errors';
         $body['error']['errors'] = array();
         foreach ($exception->getExceptions() as $key => $validationException) {
             /** @var ValidationException $validationException */
             $body['error']['errors'][$key] = array('error' => array('message' => $validationException->getMessage(), 'identifier' => $validationException->getIdentifier()), 'definition' => $validationException->getValidator()->getDefinition());
         }
     } else {
         $body['error']['global'] = $exception->getMessage();
     }
     return new JsonResponse($body, Response::HTTP_BAD_REQUEST);
 }
예제 #4
0
    /**
     * {@inheritdoc}
     */
    public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
    {
        $request->headers->set('X-Php-Ob-Level', ob_get_level());

        try {
            return $this->handleRaw($request, $type);
        } catch (\Exception $e) {
            if ($e instanceof RequestExceptionInterface) {
                $e = new BadRequestHttpException($e->getMessage(), $e);
            }
            if (false === $catch) {
                $this->finishRequest($request, $type);

                throw $e;
            }

            return $this->handleException($e, $request, $type);
        }
    }