Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
\Drupal\Core\EventSubscriber\ExceptionJsonSubscriber takes the exception message and wraps the exception message into an array and encodes it. This means we're currently getting a weird double encoding when returning an array of constraint errors
$messages = array_map(static function (ConstraintViolationInterface $violation) {
return sprintf("%s: %s", $violation->getPropertyPath(), $violation->getMessage());
}, \iterator_to_array($constraints));
throw new UnprocessableEntityHttpException(Json::encode([
'errors' => $messages,
]));
There isn't a good way to return an array of errors. We'd have to borrow something like \Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber but for the regular JSON format.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork simplytest-3190445
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
mglamanComment #6
nerdsteinLooks great thank you