Module: Safire::Errors

Defined in:
lib/safire/errors.rb

Overview

Namespace for all Safire error classes.

Every Safire error inherits from Error so consumers can rescue all Safire errors with a single rescue Safire::Errors::Error. Each subclass exposes typed, domain-specific attributes and builds its own human-readable message.

OAuth 2.0 protocol errors (TokenError, AuthError, RegistrationError) share the same HTTP-failure shape and inherit from OAuthError, which can be used as a single rescue point for any server-side OAuth failure:

rescue Safire::Errors::OAuthError => e
  puts e.status       # HTTP status code
  puts e.error_code   # OAuth2 error field

Examples:

Rescuing a specific error

begin
  tokens = client.request_access_token(code: code, code_verifier: verifier)
rescue Safire::Errors::TokenError => e
  puts e.message        # "Token request failed — HTTP 401 — invalid_grant — Code expired"
  puts e.status         # 401
  puts e.error_code     # "invalid_grant"
rescue Safire::Errors::Error => e
  puts e.message        # catch-all for any other Safire error
end

Defined Under Namespace

Modules: ReceivesFields Classes: AuthError, CertificateError, ConfigurationError, DiscoveryError, Error, NetworkError, OAuthError, RegistrationError, TokenError, ValidationError