"""Refusal codes on the Fleetmesh auth wire.
Every failed reply is `{"ok": false, "error": <code>, "detail": <sentence>}`.
The code is stable and snake_case (a key of ERRORS, which lives in
fleetmesh_core.identity.web_auth so the core refusals and the engine's share
one table); the sentence is for people and may change. Providers raise or
return either; `refusal()` builds the wire dict.
"""
from __future__ import annotations
from typing import Any, Dict, Optional
from fleetmesh_core.identity.web_auth import ERRORS, AuthRefused
__all__ = ["ERRORS", "AuthRefused", "refusal", "detail_for"]
[docs]def detail_for(code: str) -> str:
"""The default sentence for a code; the code itself if it has none."""
return ERRORS.get(code, code)
[docs]def refusal(code: str, detail: Optional[str] = None, **extra: Any) -> Dict[str, Any]:
"""The wire shape of a refused call. Extra keys (required_role, roles)
ride along after `detail`."""
out: Dict[str, Any] = {"ok": False, "error": code, "detail": detail if detail is not None else detail_for(code)}
out.update(extra)
return out