Fix domain verification error handling using CallbackError#48
Open
pauldruziak wants to merge 2 commits intosynth:mainfrom
Open
Fix domain verification error handling using CallbackError#48pauldruziak wants to merge 2 commits intosynth:mainfrom
pauldruziak wants to merge 2 commits intosynth:mainfrom
Conversation
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.
af11ce8 to
98bf51a
Compare
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."
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.