Docs menu: vestibule/error

vestibule/error

Authentication error types.

vestibule/error

Authentication error types.

AuthError(e) is an opaque error value. Instead of pattern matching on public variants, classify and inspect errors through the accessor functions in this module:

  • kind returns an ErrorKind classifier. It carries an OtherKind catch-all so future error kinds can be added without breaking exhaustive case expressions in consuming code.
  • phase returns the coarse Phase the error occurred in.
  • message returns a human-readable summary, safe to log.
  • provider_error returns sanitized provider error data when the provider returned a standard OAuth error.
  • http_status and missing_parameter expose the few additional structured fields some errors carry.
  • custom_payload returns the provider-defined payload for custom errors.
  • recovery returns stable, non-sensitive recovery metadata suitable for HTTP handlers and user-facing error pages.

Construct errors with the constructor functions (config, network, provider, and friends). The type parameter e lets third-party providers attach custom error payloads via custom; built-in strategies stay polymorphic in e.

Types

AuthError

An opaque authentication error.

Inspect values of this type with kind, phase, message, provider_error, http_status, missing_parameter, and custom_payload.

pub type AuthError(a)

ErrorKind

A stable, machine-readable error classifier.

OtherKind is a catch-all: matching on it keeps consumer case expressions exhaustive even as new kinds are introduced. Always include an OtherKind (or _) arm when matching on this type.

pub type ErrorKind {
StateMismatchKind
InvalidNonceKind
MissingCallbackParamKind
CodeExchangeKind
UserInfoKind
ProviderKind
HttpKind
DecodeKind
NetworkKind
ConfigKind
RefreshUnsupportedKind
CustomKind
OtherKind
}

Constructors

StateMismatchKind

State parameter mismatch — possible CSRF attack.

InvalidNonceKind

OIDC nonce mismatch or missing-but-expected — possible id_token replay/injection attack.

MissingCallbackParamKind

A required OAuth callback parameter was missing.

CodeExchangeKind

Failed to exchange the authorization code for tokens.

UserInfoKind

Failed to fetch user info from the provider.

ProviderKind

The provider returned a standard OAuth error response.

Known standard error codes are retained. Unknown codes, descriptions, and URIs are replaced or discarded because provider-controlled fields can echo submitted secrets.

HttpKind

The provider returned a non-success HTTP response.

DecodeKind

A provider response body could not be decoded.

NetworkKind

An HTTP request failed at the network level.

ConfigKind

Invalid configuration.

RefreshUnsupportedKind

The strategy does not support refreshing access tokens.

CustomKind

A provider-specific custom error (see custom).

OtherKind

Catch-all for kinds added in future releases.

Phase

A coarse classification of where in the OAuth flow an error occurred.

pub type Phase {
CallbackPhase
TokenExchangePhase
UserInfoPhase
ConfigPhase
ProviderPhase
TransportPhase
RefreshPhase
}

Constructors

CallbackPhase

Validating or parsing the OAuth callback request.

TokenExchangePhase

Exchanging the authorization code for tokens.

UserInfoPhase

Fetching user info from the provider.

ConfigPhase

Reading or validating configuration.

ProviderPhase

The provider returned an explicit error response.

TransportPhase

Network / HTTP transport.

RefreshPhase

Refreshing an access token.

ProviderError

Structured data from a standard OAuth provider error response.

Provider-controlled descriptions, URIs, and unknown error codes are discarded so a provider cannot echo submitted secrets into public errors.

pub type ProviderError

Recovery

Stable, non-sensitive recovery metadata for an authentication error.

The summary is safe to show to users. It never contains provider-controlled descriptions, raw response bodies, credentials, or internal error reasons.

pub type Recovery

RecoveryAction

What an application should let the user do after an authentication error.

pub type RecoveryAction {
RetryOperation
RestartAuthorization
ContactApplication
}

Constructors

RetryOperation

Retry the same operation.

RestartAuthorization

Start a new authorization flow.

ContactApplication

The application or its configuration must be changed.

Functions

code_exchange

Failed to exchange the authorization code for tokens.

pub fn code_exchange(reason: String) -> AuthError(a)

config

Invalid configuration.

pub fn config(reason: String) -> AuthError(a)

custom

A provider-specific custom error carrying a payload of type e.

pub fn custom(a) -> AuthError(a)

custom_payload

The provider-defined custom payload, for CustomKind errors.

pub fn custom_payload(AuthError(a)) -> option.Option(a)

decode

A provider response body could not be decoded.

pub fn decode(
context: String,
reason: String
) -> AuthError(a)

http

The provider returned a non-success HTTP response.

summary should be a short description of the failure. Do not include raw response bodies because providers can echo submitted secrets.

pub fn http(
status: Int,
summary: String
) -> AuthError(a)

http_status

The HTTP status code, for errors that carry one.

pub fn http_status(AuthError(a)) -> option.Option(Int)

http_summary

The short HTTP error summary, for HttpKind errors.

pub fn http_summary(AuthError(a)) -> option.Option(String)

invalid_nonce

OIDC nonce mismatch or missing-but-expected — possible id_token replay.

pub fn invalid_nonce() -> AuthError(a)

kind

The machine-readable ErrorKind classifier for this error.

pub fn kind(AuthError(a)) -> ErrorKind

message

A human-readable, log-safe summary of this error.

pub fn message(AuthError(a)) -> String

missing_callback_param

A required OAuth callback parameter was missing.

pub fn missing_callback_param(String) -> AuthError(a)

missing_parameter

The name of the missing callback parameter, for MissingCallbackParamKind.

pub fn missing_parameter(AuthError(a)) -> option.Option(String)

network

An HTTP request failed at the network level.

pub fn network(reason: String) -> AuthError(a)

new_recovery

Build recovery metadata for adapter-defined errors.

pub fn new_recovery(
RecoveryAction,
Int,
String,
String
) -> Recovery

phase

The coarse Phase this error occurred in.

pub fn phase(AuthError(a)) -> Phase

provider

The provider returned a standard OAuth error response.

pub fn provider(
code: String,
description: String,
uri: option.Option(String)
) -> AuthError(a)

provider_code

The standard OAuth error code.

pub fn provider_code(ProviderError) -> String

provider_description

A fixed, log-safe provider error description.

pub fn provider_description(ProviderError) -> String

provider_error

Structured provider error data, when the provider returned a standard OAuth error response.

pub fn provider_error(AuthError(a)) -> option.Option(ProviderError)

provider_uri

The provider error URI. This is always None; provider-controlled URIs are discarded to avoid echoing secrets.

pub fn provider_uri(ProviderError) -> option.Option(String)

recovery

Return stable recovery metadata for an authentication error.

pub fn recovery(AuthError(a)) -> Recovery

recovery_action

Return the recommended recovery action.

pub fn recovery_action(Recovery) -> RecoveryAction

recovery_code

Return the stable public error code.

pub fn recovery_code(Recovery) -> String

recovery_http_status

Return the recommended HTTP response status.

pub fn recovery_http_status(Recovery) -> Int

recovery_summary

Return the safe default user-facing summary.

pub fn recovery_summary(Recovery) -> String

refresh_unsupported

The strategy does not support refreshing access tokens.

Returned when strategy.refresh_token is called on a strategy that was built without a refresh capability (no with_refresh).

pub fn refresh_unsupported() -> AuthError(a)

state_mismatch

State parameter mismatch — possible CSRF attack.

pub fn state_mismatch() -> AuthError(a)

user_info

Failed to fetch user info from the provider.

pub fn user_info(reason: String) -> AuthError(a)