glimr/http/error_handler

Error Handler

Ever called wisp.not_found() and gotten a completely blank page? That’s because bare status-code responses have empty bodies — browsers show nothing and API clients get no clue what went wrong. This module intercepts those empty error responses and fills them with real content: an HTML error page for browsers, a JSON {"error": "..."} for APIs. Handlers never need to manually render error templates or build error JSON — it just happens.

Values

pub fn default_responses(
  response_format: response.ResponseFormat,
  handle_request: fn() -> response.Response(wisp.Body),
) -> response.Response(wisp.Body)

A single middleware entry handles both web and API error formatting by checking the response format flag. This means routes that serve both HTML and JSON traffic don’t need separate error middleware — the format is already known from earlier in the pipeline, so we just dispatch to the right handler automatically.

Search Document