Skip to main content

Module error

Module error 

Source
Expand description

Error vocabulary and mapping.

A GraphQL response is an HTTP 200 (under application/json), so it never passes through Autumn’s problem-details filter, which is where server-side detail is normally redacted. This module is that filter for GraphQL:

  • IntoGraphqlError / GraphqlResultExt::gql turn an AutumnError into a field error. Client errors (4xx) keep their message; server errors (5xx) are logged and replaced by a generic message. The HTTP status travels in extensions.status and a stable machine-readable code in extensions.code, so a client can tell a 422 from a 503 without an HTTP status to read.
  • Validation failures carry their per-field messages in extensions.fields as well as in the message.
  • Errors a resolver produced without a code (a bare ? on some library error, ctx.data::<T>()?, …) are “unexpected”. When mask_unexpected_errors is on, the plugin replaces their message before the response leaves the process. Give an error a code to show its message to clients.

Modules§

codes
Stable values for errors[].extensions.code.

Constants§

INTERNAL_MESSAGE
The generic message a redacted or masked error carries.

Traits§

GraphqlResultExt
?-friendly conversion for resolver results.
IntoGraphqlError
Conversion into a coded, redaction-safe GraphQL error.

Functions§

code_for_status
The extensions.code for an HTTP status.
error_code
Read extensions.code off a server error, if any.
finalize_errors
Post-process a response’s errors: give every error a code, and mask unexpected execution errors when mask is on.
graphql_error
Build a coded GraphQL error: extensions.code and, when given, extensions.status.
is_execution_error
Whether error was raised during execution (it has a response path) rather than while parsing or validating the document.
request_error
Build a pre-execution ServerError carrying code and status, plus any extra extension values.