40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
"""User-facing application errors with safe, actionable messages."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
class UserFacingError(Exception):
|
|
def __init__(
|
|
self,
|
|
message: str,
|
|
*,
|
|
title: str = "Nie można wykonać diagnozy",
|
|
hint: str | None = None,
|
|
code: str = "application_error",
|
|
) -> None:
|
|
super().__init__(message)
|
|
self.title = title
|
|
self.message = message
|
|
self.hint = hint
|
|
self.code = code
|
|
|
|
|
|
class InputDataError(UserFacingError):
|
|
def __init__(self, message: str, *, hint: str | None = None, code: str = "invalid_input") -> None:
|
|
super().__init__(
|
|
message,
|
|
title="Nieprawidłowe dane wejściowe",
|
|
hint=hint,
|
|
code=code,
|
|
)
|
|
|
|
|
|
class InferenceError(UserFacingError):
|
|
def __init__(self, message: str, *, hint: str | None = None) -> None:
|
|
super().__init__(
|
|
message,
|
|
title="Model nie zakończył diagnozy",
|
|
hint=hint,
|
|
code="inference_failed",
|
|
)
|