adding result objects, renaming components
This commit is contained in:
@@ -2,11 +2,11 @@ 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, doptResponse
|
||||
from delta_barth.constants import DEFAULT_API_ERR_CODE, DEFAULT_INTERNAL_ERR_CODE
|
||||
from delta_barth.types import DataPipeStates, Status
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from delta_barth.types import ErrorDescription
|
||||
from delta_barth.types import DelBarApiError, ErrorDescription
|
||||
|
||||
|
||||
class UnspecifiedRequestType(Exception):
|
||||
@@ -26,7 +26,7 @@ class FeaturesMissingError(Exception):
|
||||
|
||||
|
||||
## ** internal error handling
|
||||
DATA_PIPELINE_ERRORS_DESCR: Final[tuple[ErrorDescription, ...]] = (
|
||||
DATA_PIPELINE_STATUS_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"),
|
||||
@@ -35,33 +35,48 @@ DATA_PIPELINE_ERRORS_DESCR: Final[tuple[ErrorDescription, ...]] = (
|
||||
|
||||
class ErrorHandler:
|
||||
def __init__(self) -> None:
|
||||
self._data_pipelines: DataPipelineErrors | None = None
|
||||
self._parse_data_pipeline_errors()
|
||||
self._pipe_states: DataPipeStates | None = None
|
||||
self._parse_data_pipe_states()
|
||||
|
||||
@property
|
||||
def data_pipelines(self) -> DataPipelineErrors:
|
||||
assert self._data_pipelines is not None, (
|
||||
def pipe_states(self) -> DataPipeStates:
|
||||
assert self._pipe_states is not None, (
|
||||
"tried to access not parsed data pipeline errors"
|
||||
)
|
||||
return self._data_pipelines
|
||||
return self._pipe_states
|
||||
|
||||
def _parse_data_pipeline_errors(self) -> None:
|
||||
if self._data_pipelines is not None:
|
||||
def _parse_data_pipe_states(self) -> None:
|
||||
if self._pipe_states is not None:
|
||||
return
|
||||
parsed_errors: dict[str, doptResponse] = {}
|
||||
for err in DATA_PIPELINE_ERRORS_DESCR:
|
||||
parsed_errors[err[0]] = doptResponse(status_code=err[1], description=err[2])
|
||||
parsed_errors: dict[str, Status] = {}
|
||||
for err in DATA_PIPELINE_STATUS_DESCR:
|
||||
parsed_errors[err[0]] = Status(status_code=err[1], description=err[2])
|
||||
|
||||
self._data_pipelines = DataPipelineErrors(**parsed_errors)
|
||||
self._pipe_states = DataPipeStates(**parsed_errors)
|
||||
|
||||
def internal_error(
|
||||
def error(
|
||||
self,
|
||||
description: str,
|
||||
message: str = "",
|
||||
err_code: int = DEFAULT_INTERNAL_ERR_CODE,
|
||||
) -> doptResponse:
|
||||
return doptResponse(
|
||||
) -> Status:
|
||||
return Status(
|
||||
status_code=err_code,
|
||||
description=description,
|
||||
message=message,
|
||||
)
|
||||
|
||||
def api_error(
|
||||
self,
|
||||
error: DelBarApiError,
|
||||
) -> Status:
|
||||
description = "Es ist ein Fehler bei der Kommunikation mit dem API-Server aufgetreten"
|
||||
message = (
|
||||
"Bitte beachten Sie die zusätzliche Fehlerausgabe des Servers in dieser Antwort"
|
||||
)
|
||||
return Status(
|
||||
status_code=DEFAULT_API_ERR_CODE,
|
||||
description=description,
|
||||
message=message,
|
||||
api_server_error=error,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user