Expose an error's HTTP status and Resend error name on `Resend::Error`

未关闭 适合新手
#266 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 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.

lib/resend/errors.rb:

attr_reader :headers

def initialize(msg, code = nil, headers = {})
  super(msg)
  @code = code      # stored, but there's no reader
  @headers = headers
end

lib/resend/request.rb:

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_locked and forge_not_enabled. A caller sending with an idempotency_key and 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 InternalServerError through check_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
  1. attr_reader :code on Resend::Error, returning the status it's already given. Additive.
  2. Keep the response's name on the error, say as attr_reader :name, matching resend-node's field, passed by handle_error! as a new optional argument so existing Resend::Error.new(msg, code, headers) calls keep working.
  3. Optionally, classes for the statuses that fall through today: a ConflictError for 409, and 502–504 mapped to ServerError subclasses.

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 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

resend/resend-ruby 的其他 Issue

查看 resend/resend-ruby 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。