Repository navigation
fix: map 401 and 403 validation_error to ValidationError - #305
Conversation
|
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 |
|
@felipefreitag @dielduarte when you have a moment, could one of you take a look? It's a small change: 401 and 403 |
7646b70 to
bdc3f96
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #305 +/- ##
===========================================
+ Coverage 82.66% 97.62% +14.96%
===========================================
Files 4 89 +85
Lines 75 5521 +5446
===========================================
+ Hits 62 5390 +5328
- Misses 13 131 +118 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ases validation_error now also covers 401 (invalid API key) and 403 (unverified domain, testing-mode recipient, inbox limit), so pointing at missing fields is misleading.
dielduarte
left a comment
There was a problem hiding this comment.
thanks for the contribution!!
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) and 403 (unverified domain, testing-mode restriction) toValidationErrorso they raise a catchable error with asuggested_actioninstead of falling back to a plainResendError. Backward compatible:ValidationErrorsubclassesResendError, andcode,message,error_type, andheadersstay the same. Also updatesValidationError'ssuggested_actionto a generic message, sincevalidation_errornow covers auth and domain problems, not just missing fields.invalid_api_keyis left untouched; docs only listvalidation_errorfor 401/403, soInvalidApiKeyErrormay no longer be raised. Bumps the package version to 2.53.0.Written for commit 1a8be33. Summary will update on new commits.