rizer.spice.backend.api.errors#

Shared HTTP-exception translation for the Spice API routers.

Attributes#

Functions#

translate_exceptions(...)

Translate ValueError/TypeError/any other exception into an HTTPException.

Module Contents#

rizer.spice.backend.api.errors.logger#
rizer.spice.backend.api.errors.P#
rizer.spice.backend.api.errors.R#
rizer.spice.backend.api.errors.translate_exceptions(action: str) collections.abc.Callable[[collections.abc.Callable[P, R]], collections.abc.Callable[P, R]]#

Translate ValueError/TypeError/any other exception into an HTTPException.

action names what the wrapped endpoint does, used in the 500 response’s detail and the logged traceback (e.g. “RLLC simulation”, “building plot data”).

Parameters:

action (str) – Short description of the endpoint’s operation.

Returns:

A decorator. ValueError/TypeError become a 400 with str(e) as detail; any other exception becomes a 500 with a logged traceback and f”{action} failed: {type(e).__name__}: {e}” as detail. An HTTPException raised inside the endpoint (e.g. a deliberate 404) passes through unchanged.

Return type:

Callable