tests for new api errors

This commit is contained in:
2025-03-05 15:05:23 +01:00
parent c375d8e9d4
commit e60cc99583
2 changed files with 56 additions and 15 deletions

View File

@@ -6,7 +6,7 @@ from delta_barth.constants import DEFAULT_API_ERR_CODE, DEFAULT_INTERNAL_ERR_COD
from delta_barth.types import DataPipeStates, Status
if TYPE_CHECKING:
from delta_barth.types import DelBarApiError, ErrorDescription
from delta_barth.types import DelBarApiError, StatusDescription
class UnspecifiedRequestType(Exception):
@@ -26,14 +26,14 @@ class FeaturesMissingError(Exception):
## ** internal error handling
DATA_PIPELINE_STATUS_DESCR: Final[tuple[ErrorDescription, ...]] = (
DATA_PIPELINE_STATUS_DESCR: Final[tuple[StatusDescription, ...]] = (
("SUCCESS", 0, "Erfolg"),
("TOO_FEW_POINTS", 1, "Datensatz besitzt nicht genügend Datenpunkte"),
("BAD_QUALITY", 2, "Prognosequalität des Modells unzureichend"),
)
class ErrorHandler:
class StateHandler:
def __init__(self) -> None:
self._pipe_states: DataPipeStates | None = None
self._parse_data_pipe_states()
@@ -50,7 +50,7 @@ class ErrorHandler:
return
parsed_errors: dict[str, Status] = {}
for err in DATA_PIPELINE_STATUS_DESCR:
parsed_errors[err[0]] = Status(status_code=err[1], description=err[2])
parsed_errors[err[0]] = Status(code=err[1], description=err[2])
self._pipe_states = DataPipeStates(**parsed_errors)
@@ -58,10 +58,18 @@ class ErrorHandler:
self,
description: str,
message: str = "",
err_code: int = DEFAULT_INTERNAL_ERR_CODE,
code: int = DEFAULT_INTERNAL_ERR_CODE,
) -> Status:
lower_bound = DEFAULT_INTERNAL_ERR_CODE
upper_bound = DEFAULT_API_ERR_CODE
if code < lower_bound or code > upper_bound:
raise ValueError(
f"Custom error codes mus be between default "
f"values of {lower_bound}-{upper_bound}"
)
return Status(
status_code=err_code,
code=code,
description=description,
message=message,
)
@@ -75,7 +83,7 @@ class ErrorHandler:
"Bitte beachten Sie die zusätzliche Fehlerausgabe des Servers in dieser Antwort"
)
return Status(
status_code=DEFAULT_API_ERR_CODE,
code=DEFAULT_API_ERR_CODE,
description=description,
message=message,
api_server_error=error,