class UnprocessableHttpEntityExceptionNormalizer extends HttpExceptionNormalizer
{ /**
* {@inheritdoc}
*/
protected function buildErrorObjects(HttpException
$exception) { /** @var \Drupal\jsonapi\Exception\UnprocessableHttpEntityException $exception */
$errors = parent::
buildErrorObjects($exception);
$error =
$errors[0
];
unset($error['links'
]);
$errors =
[];
$violations =
$exception->
getViolations();
$entity_violations =
$violations->
getEntityViolations();
foreach ($entity_violations as $violation) { /** @var \Symfony\Component\Validator\ConstraintViolation $violation */
$error['detail'
] = 'Entity is not valid: '
.
$violation->
getMessage();
$error['source'
]['pointer'
] = '/data';