fix(exceptions): correct status code for validation errors

Updated the status code for ValidationException responses from 422 to 400 to align with HTTP standards.
This commit is contained in:
Jérémy Munsch 2026-08-12 17:00:15 +02:00
parent 899bb42964
commit 31ae87f358
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4

View file

@ -31,7 +31,7 @@ final readonly class ApiExceptionRenderer
$e instanceof ValidationException => response()->json([
'type' => (string) $baseUri->withPath('/errors/' . ApiErrorCode::ValidationError->value),
'title' => ApiErrorCode::ValidationError->title(),
'status' => 422,
'status' => 400,
'detail' => $e->getMessage(),
'invalidParams' => array_values(array_map(
static function (int | string $field, mixed $messages): array {
@ -52,15 +52,22 @@ final readonly class ApiExceptionRenderer
array_keys($e->errors()),
array_values($e->errors())
)),
], 422, ['Content-Type' => self::CONTENT_TYPE]),
], 400, ['Content-Type' => self::CONTENT_TYPE]),
$e instanceof \DomainException => response()->json([
'type' => (string) $baseUri->withPath('/errors/' . ApiErrorCode::BadRequest->value),
'title' => ApiErrorCode::BadRequest->title(),
'status' => 400,
'detail' => $e->getMessage(),
'instance' => $request->getPathInfo(),
], 400, ['Content-Type' => self::CONTENT_TYPE]),
'type' => (string) $baseUri->withPath('/errors/' . ApiErrorCode::ValidationError->value),
'title' => ApiErrorCode::ValidationError->title(),
'status' => 422,
'detail' => $e->getMessage(),
'instance' => $request->getPathInfo(),
'invalidParams' => [
[
'name' => 'domain_invariant',
'reason' => $e->getMessage(),
],
],
], 422, ['Content-Type' => self::CONTENT_TYPE]),
default => response()->json([
'type' => (string) $baseUri->withPath('/errors/' . ApiErrorCode::InternalError->value),