DecaneDocs
ReferenceError handling
Reference

Error handling

One enum, DecaneError, with three variants. It is #[non_exhaustive], so keep a wildcard arm.

rust
use decane::{ApiErrorCode, DecaneError};

match decane.verify_email_code(email, code).await {
    Ok(session) => { /* signed in */ }
    Err(DecaneError::Api { code: ApiErrorCode::InvalidCode, .. }) => { /* ask again */ }
    Err(DecaneError::Api { code, status, .. }) => { /* status 0: never reached Decane */ }
    Err(err) => return Err(err.into()),
}

Variants

  • Auth { reason, message, source }: the token cannot be trusted. reason is AuthErrorReason::InvalidToken, MissingUid or ProjectMismatch.
  • Api { code, status, message, source }: a backend call failed. status is the HTTP status, 0 when the request never got a response.
  • Config(String): a missing key or secret, an empty argument, a malformed verification key. Raised before any network call.

Helpers: is_auth(), auth_reason(), api_code(), status().

ApiErrorCode

ApiErrorCode implements Display and FromStr with the wire strings (INVALID_CODE, …), so logs read the same as the Node SDK’s.

CodeMeaning
InvalidCodeEmail or SMS code wrong or expired
AuthFailedProvider token rejected
InvalidTokenCustom-auth JWT rejected
NoProvider, AmbiguousProvider, MissingClaimCustom-auth provider configuration
InvalidApiKey, AppIdMismatchCredential problems
SmsNotConfiguredPhone sign-in on a deployment with no SMS provider
KingsChatNotConfigured, KingsChatUnavailableKingsChat setup, or an upstream outage
InvalidRecord, NotFound, UnauthorizedRecord calls
ServerWalletsDisabled, InvalidIdentifier, WalletExists, WalletFrozen, RetryLater, EnclaveUnavailableUser and wallet creation
RateLimitedHTTP 429 with no envelope
Unknown, NetworkErrorUnparseable response, or the request never completed (status 0)
Other(String)A code this version does not know by name; the wire string is kept