from collections.abc import Callable from typing import TypeVar from fastapi import HTTPException, status T = TypeVar("T") ERROR_CODES = { "DemNotConfiguredError": "DEM_NOT_CONFIGURED", "LandcoverNotConfiguredError": "LANDCOVER_NOT_CONFIGURED", "RasterNotConfiguredError": "RASTER_NOT_CONFIGURED", } def as_501(call: Callable[[], T]) -> T: try: return call() except NotImplementedError as exc: raise HTTPException( status_code=status.HTTP_501_NOT_IMPLEMENTED, detail={ "code": ERROR_CODES.get(type(exc).__name__, "NOT_IMPLEMENTED"), "detail": str(exc), }, ) from exc