diff --git a/distribution/index.md b/distribution/index.md index 5a8fe234a8f..be625198adb 100644 --- a/distribution/index.md +++ b/distribution/index.md @@ -626,14 +626,7 @@ Now try to add another book by issuing a `POST` request to `/books` with the fol } ``` -Oops, we forgot to add the title. Submit the request anyway, you should get a 500 error with the following message: - -> An exception occurred while executing 'INSERT INTO book [...] VALUES [...]' with params [...]: -> SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null - -Did you notice that the error was automatically serialized in JSON-LD and respects the Hydra Core vocabulary for errors? -It allows the client to easily extract useful information from the error. Anyway, it's bad to get a SQL error when submitting -a request. It means that we didn't use a valid input, and [it's a bad and dangerous practice](https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html). +The book is successfully created but there is a problem; we did not give it a title. It makes no sense to create a book record without a title so we really should have some validation measures in place to prevent this from being possible. API Platform comes with a bridge with [the Symfony Validator Component](https://symfony.com/doc/current/validation.html). Adding some of [its numerous validation constraints](https://symfony.com/doc/current/validation.html#supported-constraints) @@ -654,6 +647,11 @@ Modify the following files as described in these patches: */ + #[Assert\Isbn] public ?string $isbn = null; + + * @ORM\Column + */ ++ #[Assert\NotBlank] + public string $title = ''; * @ORM\Column(type="text") */