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:
parent
899bb42964
commit
31ae87f358
1 changed files with 15 additions and 8 deletions
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue