Skip to content

Commit be2a3eb

Browse files
authored
doc: update validation exception code to 422 (#1206)
1 parent 8848150 commit be2a3eb

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

core/errors.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ api_platform:
7979
ApiPlatform\Core\Exception\FilterValidationException: 400
8080
Doctrine\ORM\OptimisticLockException: 409
8181

82+
# Validation exception
83+
ApiPlatform\Core\Bridge\Symfony\Validator\Exception\ValidationException: !php/const Symfony\Component\HttpFoundation\Response::HTTP_UNPROCESSABLE_ENTITY
84+
8285
# Custom mapping
8386
App\Exception\ProductNotFoundException: 404 # Here is the handler for our custom exception
8487
```

core/graphql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ It's because a built-in [custom exception normalizer](#custom-exception-normaliz
12921292
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).
12931293

12941294
For some specific exceptions, built-in [custom exception normalizers](#custom-exception-normalizer) are also used to add more information.
1295-
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.
1295+
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.
12961296

12971297
#### Custom Exception Normalizer
12981298

core/validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ final class MinimalPropertiesValidator extends ConstraintValidator
102102
}
103103
```
104104

105-
If the data submitted by the client is invalid, the HTTP status code will be set to `400 Bad Request` and the response's
105+
If the data submitted by the client is invalid, the HTTP status code will be set to `422 Unprocessable Entity` and the response's
106106
body will contain the list of violations serialized in a format compliant with the requested one. For instance, a validation
107107
error will look like the following if the requested format is JSON-LD (the default):
108108

distribution/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class BooksTest extends ApiTestCase
152152
'isbn' => 'invalid',
153153
]]);
154154

155-
$this->assertResponseStatusCodeSame(400);
155+
$this->assertResponseStatusCodeSame(422);
156156
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
157157

158158
$this->assertJsonContains([

0 commit comments

Comments
 (0)