Coverage for src/counter_os/application/dtos/error_response.py: 100%
16 statements
« prev ^ index » next coverage.py v7.17.5, created at 2026-11-29 05:31 -0600
« prev ^ index » next coverage.py v7.17.5, created at 2026-11-29 05:31 -0600
1from dataclasses import dataclass
2from enum import StrEnum
3from typing import Any
6class ErrorCode(StrEnum):
7 COUNT_CANNOT_BE_NEGATIVE = "COUNT_CANNOT_BE_NEGATIVE"
8 COUNT_CANNOT_BE_GREATER_THAN_100 = "COUNT_CANNOT_BE_GREATER_THAN_100"
9 VALIDATION_ERROR = "VALIDATION_ERROR"
12@dataclass(frozen=True)
13class ErrorResponse:
14 """Standardized error response for an application-layer request"""
16 code: ErrorCode
17 message: str
18 details: dict[str, Any] | None = None
20 @classmethod
21 def count_cannot_be_negative(cls, value: int) -> ErrorResponse:
22 return cls(
23 code=ErrorCode.COUNT_CANNOT_BE_NEGATIVE,
24 message=f"{value} is a negative value and count cannot be negative",
25 )
27 @classmethod
28 def count_cannot_be_greater_than_100(cls, value: int) -> ErrorResponse:
29 return cls(
30 code=ErrorCode.COUNT_CANNOT_BE_GREATER_THAN_100,
31 message=f"{value} is greater than 100 and count cannot be greater than 100",
32 )