new architecture for error handling
This commit is contained in:
@@ -1,3 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
from delta_barth.constants import DEFAULT_INTERNAL_ERR_CODE
|
||||
from delta_barth.types import DataPipelineErrors, doptResponseError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from delta_barth.types import ErrorDescription
|
||||
|
||||
|
||||
class UnspecifiedRequestType(Exception):
|
||||
"""exception raised if for a given API endpoint a not defined operation is requested"""
|
||||
|
||||
@@ -12,3 +23,45 @@ class ApiConnectionError(Exception):
|
||||
|
||||
class FeaturesMissingError(Exception):
|
||||
"""exception raised if needed features are missing"""
|
||||
|
||||
|
||||
## ** internal error handling
|
||||
DATA_PIPELINE_ERRORS_DESCR: Final[tuple[ErrorDescription, ...]] = (
|
||||
("SUCCESS", 0, "Erfolg"),
|
||||
("TOO_FEW_POINTS", 1, "Datensatz besitzt nicht genügend Datenpunkte"),
|
||||
("BAD_QUALITY", 2, "Prognosequalität des Modells unzureichend"),
|
||||
)
|
||||
|
||||
|
||||
class ErrorManager:
|
||||
def __init__(self) -> None:
|
||||
self._data_pipelines: DataPipelineErrors | None = None
|
||||
self._parse_data_pipeline_errors()
|
||||
|
||||
@property
|
||||
def data_pipelines(self) -> DataPipelineErrors:
|
||||
assert self._data_pipelines is not None, (
|
||||
"tried to access not parsed data pipeline errors"
|
||||
)
|
||||
return self._data_pipelines
|
||||
|
||||
def _parse_data_pipeline_errors(self) -> None:
|
||||
if self._data_pipelines is not None:
|
||||
return
|
||||
parsed_errors: dict[str, doptResponseError] = {}
|
||||
for err in DATA_PIPELINE_ERRORS_DESCR:
|
||||
parsed_errors[err[0]] = doptResponseError(status_code=err[1], description=err[2])
|
||||
|
||||
self._data_pipelines = DataPipelineErrors(**parsed_errors)
|
||||
|
||||
def internal_error(
|
||||
self,
|
||||
description: str,
|
||||
message: str = "",
|
||||
err_code: int = DEFAULT_INTERNAL_ERR_CODE,
|
||||
) -> doptResponseError:
|
||||
return doptResponseError(
|
||||
status_code=err_code,
|
||||
description=description,
|
||||
message=message,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user