Expose an error's HTTP status and Resend error name on `Resend::Error`
维护者通常 5 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- ruby
调研方向
先从 lib/resend/errors.rb 和 lib/resend/request.rb 开始,然后检查现有的错误初始化和 Request#handle_error! 测试。该 issue 提议公开 HTTP 状态并保留响应错误名称,同时兼容现有的构造函数调用;请决定是否纳入可选的错误类映射。完成标准是调用方能够读取新增的错误详情,并且测试覆盖现有和新增的错误处理。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Ruby
- 星标
- 55
- 派生
- 12
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 1
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
resend/resend-ruby 的其他 Issue
-
难度 5/5 一周以上 新手友好度 10/100
resend/resend-ruby#16 ·
维护者通常 5 天内回复
查看 resend/resend-ruby 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 79/100
simp/rubygem-simp-cli#238 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
simp/pupmod-simp-pki#163 ·
-
难度 1/5 1 小时以内 新手友好度 82/100
SeleniumHQ/selenium#18323 ·
维护者通常 1 天内回复
-
Bug Ruby
难度 2/5 1-3 小时 新手友好度 76/100
getsentry/sentry-ruby#3211 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 69/100
danbooru/fumimi-discord#63 ·