diff --git a/src/Presentation/Api/V1/Exceptions/ApiExceptionRenderer.php b/src/Presentation/Api/V1/Exceptions/ApiExceptionRenderer.php index f3e9ac6..06416de 100644 --- a/src/Presentation/Api/V1/Exceptions/ApiExceptionRenderer.php +++ b/src/Presentation/Api/V1/Exceptions/ApiExceptionRenderer.php @@ -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),