Fix domain verification error handling using CallbackError #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
DomainVerificationErrorclass withOmniAuth::Strategies::OAuth2::CallbackErrorto ensure proper error handling.Key Changes
DomainVerificationErrorclass (inherited fromOmniAuth::Error)OmniAuth::Strategies::OAuth2::CallbackErrorfor domain verification failuresCallbackErrorwith:domain_verification_failedsymbolomniauthtoomniauth-oauth2Rationale
The omniauth-oauth2 gem's
callback_phaseonly rescues specific exceptions:The previous
DomainVerificationErrorinherited fromOmniAuth::Error, which is not in this rescue clause, causing it to bubble up as an unhandled 500 error.By using
CallbackError, the error is: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 (❌):
After (✅):
Testing
Updated test in
domain_verifier_spec.rb:CallbackErrorwith:domain_verification_failedsymbolCompatibility
✅ Backward compatible - Applications using this gem don't need code changes. The error is still caught and handled through OmniAuth's standard failure mechanism.