core/modules/rest/src/Plugin/rest/resource/EntityResource.php | 3 ++- core/modules/rest/src/RequestHandler.php | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index 4acb0e0..a14ff42 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -12,6 +12,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\HttpException; +use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; /** * Represents entities as resources. @@ -272,7 +273,7 @@ protected function validate(EntityInterface $entity) { // 422 Unprocessable Entity code from RFC 4918. That way clients can // distinguish between general syntax errors in bad serializations (code // 400) and semantic errors in well-formed requests (code 422). - throw new HttpException(422, $message); + throw new UnprocessableEntityHttpException($message); } } diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php index 8e0cd74..ac35082 100644 --- a/core/modules/rest/src/RequestHandler.php +++ b/core/modules/rest/src/RequestHandler.php @@ -8,7 +8,9 @@ use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\HttpException; +use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\SerializerInterface; @@ -90,6 +92,10 @@ public function handle(RouteMatchInterface $route_match, Request $request) { $response = call_user_func_array(array($resource, $method), array_merge($parameters, array($unserialized, $request))); } catch (HttpException $e) { + if (!($e instanceof BadRequestHttpException || $e instanceof UnprocessableEntityHttpException)) { + throw $e; + } + $error['error'] = $e->getMessage(); $content = $serializer->serialize($error, $format); // Add the default content type, but only if the headers from the