Module: Supabase::Rails::Web::AuthErrorMapper
- Defined in:
- lib/supabase/rails/web/auth_error_mapper.rb
Overview
Translates ‘Supabase::Auth::Errors::*` (raised by `supabase-rb`) into the gem-stable `Supabase::Rails::AuthError` surface (`#code` + `#status`) per FR-W9. Controllers and the middleware error-shaping pipeline can rely on these stable codes/statuses without inspecting upstream classes.
Ordering note: the dispatch is a ‘case/when`, so the most specific classes must come before their ancestors. `AuthRetryableError`, `AuthSessionMissing`, `AuthInvalidCredentialsError`, `AuthInvalidJwtError`, and `AuthWeakPassword` all inherit from `CustomAuthError < AuthError`; `AuthApiError`, `AuthPKCEError`, and `AuthUnknownError` inherit directly from `AuthError`. None of them inherit from each other, so the within-leaf order is cosmetic.
Class Method Summary collapse
Class Method Details
.translate(err) ⇒ Supabase::Rails::AuthError
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/supabase/rails/web/auth_error_mapper.rb', line 25 def translate(err) = err.respond_to?(:message) ? err..to_s : err.to_s case err when ::Supabase::Auth::Errors::AuthInvalidCredentialsError AuthError.new(, AuthError::INVALID_CREDENTIALS, 401) when ::Supabase::Auth::Errors::AuthInvalidJwtError AuthError.new(, AuthError::INVALID_CREDENTIALS, 401) when ::Supabase::Auth::Errors::AuthSessionMissing AuthError.new(, AuthError::SESSION_MISSING, 401) when ::Supabase::Auth::Errors::AuthWeakPassword AuthError.new(, AuthError::WEAK_PASSWORD, 422) when ::Supabase::Auth::Errors::AuthPKCEError AuthError.new(, AuthError::PKCE_ERROR, 400) when ::Supabase::Auth::Errors::AuthRetryableError AuthError.new(, AuthError::AUTH_RETRYABLE, 503) when ::Supabase::Auth::Errors::AuthApiError map_api_error(, err.status) when ::Supabase::Auth::Errors::AuthUnknownError AuthError.new(, AuthError::AUTH_GENERIC_ERROR, 500) else AuthError.new(, AuthError::AUTH_GENERIC_ERROR, 500) end end |