/** * @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); }