From 5dda90c33bbef49b183323e1b6d955f81e79449a Mon Sep 17 00:00:00 2001 From: Ahmed EBEN HASSINE Date: Sun, 8 Nov 2020 15:36:55 +0100 Subject: [PATCH] doc: update validation exception code to 422 --- core/errors.md | 3 +++ core/graphql.md | 2 +- core/validation.md | 2 +- distribution/testing.md | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/errors.md b/core/errors.md index aa4ffe4e55d..021cb7290c3 100644 --- a/core/errors.md +++ b/core/errors.md @@ -79,6 +79,9 @@ api_platform: ApiPlatform\Core\Exception\FilterValidationException: 400 Doctrine\ORM\OptimisticLockException: 409 + # Validation exception + ApiPlatform\Core\Bridge\Symfony\Validator\Exception\ValidationException: !php/const Symfony\Component\HttpFoundation\Response::HTTP_UNPROCESSABLE_ENTITY + # Custom mapping App\Exception\ProductNotFoundException: 404 # Here is the handler for our custom exception ``` diff --git a/core/graphql.md b/core/graphql.md index 29bf277ba5e..48b6c9aa513 100644 --- a/core/graphql.md +++ b/core/graphql.md @@ -1292,7 +1292,7 @@ It's because a built-in [custom exception normalizer](#custom-exception-normaliz If you are in `dev` mode, more entries will be added in the response: `debugMessage` (containing the actual exception message, for instance in the case of a `LogicException`) and `trace` (the formatted exception trace). For some specific exceptions, built-in [custom exception normalizers](#custom-exception-normalizer) are also used to add more information. -It's the case for a `HttpException` for which the `status` entry will be added under `extensions` and for a `ValidationException` for which `status` (always 400) and `violations` entries will be added. +It's the case for a `HttpException` for which the `status` entry will be added under `extensions` and for a `ValidationException` for which `status` (by default 422) and `violations` entries will be added. #### Custom Exception Normalizer diff --git a/core/validation.md b/core/validation.md index d50913d14c1..0c964e780ac 100644 --- a/core/validation.md +++ b/core/validation.md @@ -102,7 +102,7 @@ final class MinimalPropertiesValidator extends ConstraintValidator } ``` -If the data submitted by the client is invalid, the HTTP status code will be set to `400 Bad Request` and the response's +If the data submitted by the client is invalid, the HTTP status code will be set to `422 Unprocessable Entity` and the response's body will contain the list of violations serialized in a format compliant with the requested one. For instance, a validation error will look like the following if the requested format is JSON-LD (the default): diff --git a/distribution/testing.md b/distribution/testing.md index a868658e107..1dac7523129 100644 --- a/distribution/testing.md +++ b/distribution/testing.md @@ -152,7 +152,7 @@ class BooksTest extends ApiTestCase 'isbn' => 'invalid', ]]); - $this->assertResponseStatusCodeSame(400); + $this->assertResponseStatusCodeSame(422); $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); $this->assertJsonContains([