Skip to content

Adopt StructuredError bubbling standard on governance surfaces#53

Merged
AquiGorka merged 2 commits into
mainfrom
fix/structured-errors
Jul 8, 2026
Merged

Adopt StructuredError bubbling standard on governance surfaces#53
AquiGorka merged 2 commits into
mainfrom
fix/structured-errors

Conversation

@AquiGorka

Copy link
Copy Markdown
Contributor

What

Adopts the StructuredError bubbling standard on council-platform's governance surfaces, mirroring the already-merged provider-platform implementation. Errors are wrapped with context (preserving the original as the cause chain into logs/OTel) and translated to a structured { status, code, message, details } response only at the API edge.

Why

council-platform already had the PlatformError class, the ErrorResponse schema, and the PIPE_APIError edge pipeline — but only the JWT middleware used them. Every route handler instead did ad-hoc try/catch → ctx.response.body = { message } (no code/status/details), and services threw raw new Error(...). This brings the whole governance path onto the standard so council-console can consume machine-readable error codes.

Changes

Edge boundary

  • New global Oak errorMiddleware (wired outermost in main.ts): catches anything thrown downstream, logs it with the full cause chain + correlation ids (requestId/traceId), and translates it via the existing PIPE_APIError pipeline. Handlers/services now throw; the redacted api projection is all that reaches the client.
  • PlatformError now preserves the wrapped original as the native Error cause, and the logger flattens the cause chain (msg <- cause <- cause) and renders correlation ids.
  • Added 503 Service Unavailable to the allowed error-status set (dependency-unavailable, e.g. channel on-chain read).

Error catalog (wrap-with-cause)

  • Per-domain PlatformError subclasses: auth challenge/signature (COUNCIL_AUTH_*), escrow (ESCROW_*), channel-state (CHANNEL_*).
  • Shared HTTP request errors (HTTP_REQ_*: validation, not-found, conflict, forbidden, invalid-body, id-required) and council-specific (HTTP_COUNCIL_*: missing-council-id, council-not-found).
  • Replaced raw throw new Error(...) and ad-hoc { message } bodies across auth, providers, channels, jurisdictions, metadata, escrow, join-requests, sign, and public join-request. jwtMiddleware and the council-auth service now throw structured errors.

Tests

  • Route handlers/middleware through a runHandler/runMiddleware edge helper so error-path tests assert the structured body; added error-catalog and logger cause-chain unit tests.
  • deno fmt/lint/check src/main.ts green; 65 unit + 185 integration passing.

Note: StructuredError is not exported by moonlight-sdk 0.11.1, so this uses council-platform's existing local PlatformError/ErrorResponse (matching provider-platform's shape).

Pairs with the council-console consumer PR.

AquiGorka added 2 commits July 6, 2026 13:59
…I edge

Add a global Oak error middleware that logs any thrown error with its full
cause chain plus correlation ids (requestId/traceId) and translates it to the
structured { status, code, message, details } ErrorResponse via the existing
PIPE_APIError edge pipeline — mirroring provider-platform.

- PlatformError now preserves the wrapped original as the native Error cause
  so the chain flows into logs/OTel (logger flattenCauses); the redacted api
  projection is all that reaches the client.
- Add per-domain PlatformError subclasses (auth challenge/signature, escrow,
  channel-state) and shared HTTP request errors (validation, not-found,
  conflict, forbidden, invalid-body); replace raw throw new Error and ad-hoc
  { message } handler bodies across the governance routes.
- jwtMiddleware and council-auth service now throw structured errors instead
  of hand-writing responses.
- Tests exercise the structured responses via a runHandler/runMiddleware edge
  helper; add error-catalog and logger cause-chain unit tests.
@AquiGorka AquiGorka requested a review from pselle July 6, 2026 18:05
@AquiGorka AquiGorka merged commit 4d8532e into main Jul 8, 2026
8 checks passed
@AquiGorka AquiGorka deleted the fix/structured-errors branch July 8, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant