- endpointy /workdays/add, is-workday, next, previous, between - /holidays, /countries (filtr eu), /markets, /health, /version - data svatku z knihovny holidays 0.109, vsech 27 zemi EU vcetne regionu - vychozi zeme CZ a cestina pres DEFAULT_COUNTRY a DEFAULT_LANGUAGE - vlastni vikend, extra_holidays a extra_workdays v requestu - testy logiky, API a testy proti realnym kalendarum - CLAUDE.md s povinnym overenim vysledku proti realite - dokumentace ve slozce documentation - .gitignore: vyjimka pro app/lib
61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
"""Application errors.
|
|
|
|
Every failure carries a machine readable error_code and a message in Czech,
|
|
because the message is shown to the caller.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
class ServiceError(Exception):
|
|
error_code = "internal_error"
|
|
status_code = 500
|
|
|
|
def __init__(self, message: str, detail: dict | None = None) -> None:
|
|
super().__init__(message)
|
|
self.message = message
|
|
self.detail = detail or {}
|
|
|
|
def to_dict(self) -> dict:
|
|
payload: dict = {"error_code": self.error_code, "message": self.message}
|
|
if self.detail:
|
|
payload["detail"] = self.detail
|
|
return payload
|
|
|
|
|
|
class InvalidRequestError(ServiceError):
|
|
error_code = "invalid_request"
|
|
status_code = 400
|
|
|
|
|
|
class InvalidDateError(ServiceError):
|
|
error_code = "invalid_date"
|
|
status_code = 400
|
|
|
|
|
|
class UnknownCountryError(ServiceError):
|
|
error_code = "unknown_country"
|
|
status_code = 400
|
|
|
|
|
|
class UnknownMarketError(ServiceError):
|
|
error_code = "unknown_market"
|
|
status_code = 400
|
|
|
|
|
|
class UnknownRegionError(ServiceError):
|
|
error_code = "unknown_region"
|
|
status_code = 400
|
|
|
|
|
|
class UnknownCategoryError(ServiceError):
|
|
error_code = "unknown_category"
|
|
status_code = 400
|
|
|
|
|
|
class OutOfRangeError(ServiceError):
|
|
"""The date or the computed result lies outside the years the calendar covers."""
|
|
|
|
error_code = "out_of_range"
|
|
status_code = 400
|