Skip to content

Commit

Permalink
fix: Uniformize custom-form error JSON response with other form-error…
Browse files Browse the repository at this point in the history
… responses
  • Loading branch information
ambroisemaupate committed May 17, 2022
1 parent 2a4f498 commit a817fa4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Controller/CustomFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ protected function getTranslation(string $_locale = 'fr'): TranslationInterface
$translation = $this->registry
->getRepository(TranslationInterface::class)
->findOneBy([
'locale' => $_locale
]);
'locale' => $_locale
]);
if (null === $translation) {
throw new NotFoundHttpException('Translation does not exist.');
}
Expand Down Expand Up @@ -163,11 +163,12 @@ public function postAction(Request $request, int $id, string $_locale = 'fr'): R

if (is_array($mixed) && $mixed['formObject'] instanceof FormInterface) {
if ($mixed['formObject']->isSubmitted()) {
$errorPayload = [
'status' => Response::HTTP_BAD_REQUEST,
'errorsPerForm' => $this->formErrorSerializer->getErrorsAsArray($mixed['formObject'])
];
return new JsonResponse(
$this->serializer->serialize(
$this->formErrorSerializer->getErrorsAsArray($mixed['formObject']),
'json'
),
$this->serializer->serialize($errorPayload, 'json'),
Response::HTTP_BAD_REQUEST,
$headers,
true
Expand Down

0 comments on commit a817fa4

Please sign in to comment.