Expose an error's HTTP status and Resend error name on `Resend::Error`
I maintainer di solito rispondono entro 5 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- ruby
- Ambito
- backend-api-design
Direzione di ricerca
Inizia da lib/resend/errors.rb e lib/resend/request.rb, poi controlla i test esistenti per l’inizializzazione degli errori e Request#handle_error!. L’issue propone di esporre lo stato HTTP e mantenere il nome dell’errore della risposta, preservando la compatibilità con le chiamate esistenti al costruttore; decidi se includere le mappature facoltative delle classi di errore. Il lavoro è completato quando i chiamanti possono leggere i dettagli di errore aggiunti e i test coprono la gestione degli errori esistente e quella nuova.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Ruby
- Stelle
- 55
- Fork
- 12
- Merge medio
- 4g 2h
- PR unite (30g)
- 1
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di resend/resend-ruby
-
Dependency DashboardAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
resend/resend-ruby#16 ·
I maintainer di solito rispondono entro 5 giorni
Tutte le issue di resend/resend-ruby
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
simp/rubygem-simp-cli#238 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
simp/pupmod-simp-pki#163 ·
-
Status: Pending
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
OpenNebula/one#8279 · 1 reazione ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
SeleniumHQ/selenium#18323 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Ruby
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
getsentry/sentry-ruby#3211 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni