Expose an error's HTTP status and Resend error name on `Resend::Error`
Maintainers usually reply within 5 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- ruby
- Domain
- backend-api-design
Research direction
Start with lib/resend/errors.rb and lib/resend/request.rb, then check existing tests for error initialization and Request#handle_error!. The issue proposes exposing the HTTP status and preserving the response error name while keeping existing constructor calls compatible; decide whether to include the optional error class mappings. Done when callers can read the added error details and tests cover existing and new error handling.
Written by the indexing model from the issue text.
Description
Summary
A caller can't tell apart the errors the gem raises as the same class without reaching into the exception's internals. Resend::Error is given the response's HTTP status and keeps it in @code, but defines no reader for it. Request#handle_error! keeps the response's message and drops its name (invalid_idempotent_request, concurrent_idempotent_requests, …) entirely.
attr_reader :headers
def initialize(msg, code = nil, headers = {})
super(msg)
@code = code # stored, but there's no reader
@headers = headers
end
def handle_error!(data, resp = nil)
code = data[:statusCode]
body = data[:message] # data[:name] isn't kept
# ...
error_class = Resend::Error::ERRORS[code] || Resend::Error
raise error_class.new(body, code, headers)
end
Where it bites
ERRORS has no entry for 409 or for 502–504, so each of those raises the base Resend::Error, with nothing public to tell them apart:
- The four 409s call for different handling. The error reference documents
concurrent_idempotent_requests(try again later, with the same key),invalid_idempotent_request(change the key or the payload),resource_lockedandforge_not_enabled. A caller sending with anidempotency_keyand retrying after a timeout has to know which one it got: retrying under the same key is right for the first and refused for 24 hours for the second. - A 502, 503 or 504 with a JSON body raises the same base class as those 409s, so a transient outage can't be told from a refusal no retry fixes. (A body that isn't JSON becomes
InternalServerErrorthroughcheck_json!.)
Today the only ways to tell are error.instance_variable_get(:@code) and matching error.message, whose wording isn't a contract.
For comparison
resend-node answers every error with { message, statusCode, name } (ErrorResponse in src/interfaces.ts), name typed against the documented codes.
Possible directions
attr_reader :codeonResend::Error, returning the status it's already given. Additive.- Keep the response's
nameon the error, say asattr_reader :name, matching resend-node's field, passed byhandle_error!as a new optional argument so existingResend::Error.new(msg, code, headers)calls keep working. - Optionally, classes for the statuses that fall through today: a
ConflictErrorfor 409, and 502–504 mapped toServerErrorsubclasses.
1 and 2 are the smallest change and would be enough on their own.
- Dominant language
- Ruby
- Stars
- 55
- Forks
- 12
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 1
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from resend/resend-ruby
-
Dependency DashboardOpen
Difficulty 5/5 Over a week Newbie friendliness 10/100
resend/resend-ruby#16 ·
Maintainers usually reply within 5 days
All issues in resend/resend-ruby
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
TheOdinProject/curriculum#31548 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 74/100
-
needs verification
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 13 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
palladius/rails8-app-on-gcp#244 ·
Maintainers usually reply within 1 day