Skip to content

Conversation

@pauldruziak
Copy link

@pauldruziak pauldruziak commented Oct 16, 2025

synth#48

Problem

Users experiencing domain verification failures currently see 500 Internal Server Errors instead of proper authentication failure messages. This creates a poor user experience and makes debugging difficult, as errors appear in exception tracking systems rather than being handled gracefully through OmniAuth's failure callback mechanism.

Solution

Replace the custom DomainVerificationError class with OmniAuth::Strategies::OAuth2::CallbackError to ensure proper error handling.

Key Changes

  • Removes custom DomainVerificationError class (inherited from OmniAuth::Error)
  • Uses OmniAuth::Strategies::OAuth2::CallbackError for domain verification failures
  • Updates tests to expect CallbackError with :domain_verification_failed symbol
  • Changes require statement from omniauth to omniauth-oauth2

Rationale

The omniauth-oauth2 gem's callback_phase only rescues specific exceptions:

rescue ::OAuth2::Error, CallbackError => e
  fail!(:invalid_credentials, e)
end

The previous DomainVerificationError inherited from OmniAuth::Error, which is not in this rescue clause, causing it to bubble up as an unhandled 500 error.

By using CallbackError, the error is:

  • ✅ Caught by the existing rescue clause
  • ✅ Converted to an OmniAuth failure automatically
  • ✅ Redirected to the failure path with a proper error message

Pattern Consistency

This follows the established pattern used by omniauth-google-oauth2 for hosted domain verification, ensuring consistency across the OmniAuth ecosystem.

Error Handling Flow

Before (❌):

Domain verification fails → DomainVerificationError → Not caught → 500 error

After (✅):

Domain verification fails → CallbackError → Caught by rescue → OmniAuth failure callback → User-friendly error

Testing

Updated test in domain_verifier_spec.rb:

  • Expects CallbackError with :domain_verification_failed symbol
  • Verifies error message includes "not a verified domain"
  • Ensures structured error data for proper handling

Compatibility

Backward compatible - Applications using this gem don't need code changes. The error is still caught and handled through OmniAuth's standard failure mechanism.

Changes:
- Replace custom DomainVerificationError (inheriting from OmniAuth::Error)
  with OmniAuth::Strategies::OAuth2::CallbackError
- This ensures the error is properly caught by omniauth-oauth2's
  callback_phase rescue clause instead of bubbling up as a 500 error
- Update test to expect CallbackError with :domain_verification_failed symbol

Rationale:
The omniauth-oauth2 gem's callback_phase only rescues specific error types:
  rescue ::OAuth2::Error, CallbackError => e

The previous DomainVerificationError inherited from OmniAuth::Error, which
is not in the rescue clause, causing it to bubble up as an unhandled 500 error.

By using CallbackError (the same pattern used by omniauth-google-oauth2 for
hosted domain verification), the error is automatically caught and converted
to a proper OmniAuth failure with fail!(:invalid_credentials, e).

This provides a better user experience with proper error handling and redirects
instead of 500 error pages.
@pauldruziak pauldruziak self-assigned this Oct 16, 2025
Updated the test expectation to match the new error type used in the
domain verifier. The test now properly expects CallbackError with
:domain_verification_failed symbol."
@pauldruziak
Copy link
Author

PR in original repo synth#48

@pauldruziak pauldruziak requested a review from jpcamara October 16, 2025 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants