示例#1
0
 /**
  * Create violation error response
  *
  * @param ViolationListException $exception
  *
  * @return JsonResponse
  */
 public function createViolationErrorResponse(ViolationListException $exception)
 {
     $errorData = [];
     /** @var \Symfony\Component\Validator\ConstraintViolationInterface $violation */
     foreach ($exception->getViolationList() as $violation) {
         $errorData[$violation->getPropertyPath()] = $violation->getMessage();
     }
     // Try get code from errors storage via exception
     $errors = $this->handler->getErrors();
     $code = $errors->hasException($exception) ? $errors->getExceptionCode($exception) : 0;
     return $this->createErrorResponse($code, null, $errorData);
 }