Add email_verification_id field to BaseRequestException #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.
Description
Fixes workos#309
Introduces a new
EmailVerificationRequiredExceptionthat extendsAuthorizationExceptionto provide direct access to theemail_verification_idfield when authentication fails due to unverified email.Changes
New Exception Class (
workos/exceptions.py):EmailVerificationRequiredExceptionas a subclass ofAuthorizationExceptionemail_verification_idfrom the error response JSONHTTP Client Logic (
workos/utils/_base_http_client.py):_maybe_raise_error_by_status_codeto detect the specific error codecode: "email_verification_required", raises the new specific exceptionAuthorizationException(preserves existing behavior)Tests (
tests/test_sync_http_client.py):EmailVerificationRequiredExceptionis raised with correct fieldsAuthorizationExceptionstill works for other 403 errorsAuthorizationException(maintains backward compatibility)Key Design Decisions
EmailVerificationRequiredExceptionextendsAuthorizationExceptionrather than adding fields to the base class, providing better type safety and semantic clarityAuthorizationExceptionwill continue to workcodefield from the API response to identify this specific error conditionReview Checklist
"email_verification_required"is the correct/only error code for this scenarioBefore/After
Before:
After:
All 370 tests pass.
Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
If yes, documentation should cover:
EmailVerificationRequiredExceptionis raisedemail_verification_idfieldLink to Devin run: https://app.devin.ai/sessions/ec6b5bc71374406895201f8407f1f73c
Requested by: Deep Singhvi (@dsinghvi)