Repository navigation
fix: map 401 and 403 validation_error to ValidationError - #305
Open
m4xkushnir wants to merge 1 commit into
Open
m4xkushnir wants to merge 1 commit into
m4xkushnir wants to merge 1 commit into
Conversation
Author
|
Hi! I use Resend for all of Ventute's email and ran into this while going through the SDK's error handling. It's a small one, so happy to adjust anything, including the |
This branch has not been deployed
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.
The error docs return
validation_errorwith 400, 401 and 403.401 is "API key is invalid" on sending endpoints, and 403 covers "The
domain.comdomain is not verified" andthe testing-mode recipient restriction.
ERRORSonly hasvalidation_errorunder 400 and 422, so the 401 and 403responses come back as a plain
ResendErrorwith an emptysuggested_action, andexcept resend.ValidationErrordoesn't catch them. An unverified sending domain is probably the most common setup mistake, so it's a shame
it's the one that slips through.
This adds
validation_errorto the 401 and 403 entries, plus two tests next to the existing 400 and 422 ones.It's backward compatible because
ValidationErrorsubclassesResendError, andcode,message,error_typeand
headersstay the same.I noticed this while writing the error handling for moving Ventute (which sends all its email through Resend)
from raw
httpxcalls to the SDK.One thing I left alone on purpose. The docs no longer list
invalid_api_key, which is the only nameInvalidApiKeyErroris registered under, so I don't think that class gets raised anymore. Whether an invalid keyshould raise
InvalidApiKeyErrorinstead ofValidationErrorfelt like your call, so this PR just follows thesame name, same class rule. Happy to change it if you'd prefer the other way.
Testing
Both new tests fail on
mainand pass here. The full suite passes on Python 3.14 and 3.8 (853 tests), and flake8and mypy show nothing new.
Summary by cubic
Maps
validation_errorresponses from 401 (invalid API key on sending endpoints) and 403 (unverified domain, testing-mode recipient restriction) toValidationErrorso they carry asuggested_actionand can be caught withexcept resend.ValidationErrorinstead of falling back to a plainResendError.ValidationErrorsubclassesResendError, andcode,message,error_type, andheadersstay the same.invalid_api_keyis left untouched; the Resend error docs only listvalidation_errorfor 401/403, soInvalidApiKeyErrormay no longer be raised.Written for commit 7646b70. Summary will update on new commits.