Let a `rescue_from` handler propagate an exception instead of rendering it
还没有人认领这个 Issue。
评估
调研方向
Look at the rescue_from handling in lib/grape/middleware/error.rb and lib/grape/dsl/inside_route.rb. Understand how exceptions are caught and redispatched since #2703. The change involves adding a propagate option to rescue_from, similar to the raise_rendering_errors config. Check existing tests for rescue_from to see how to add new behavior.
由索引模型根据 Issue 内容生成。
描述
Since #2703 (3.3.0) an exception raised inside a rescue_from block is caught and redispatched instead of escaping the middleware stack. That fixed #2482, and it also removed the only way an app could let a specific exception class reach Rack middleware mounted above Grape. There's no opt-out today.
The case I hit: Rails' ActiveRecord::Middleware::DatabaseSelector routes a request to a read replica, and a custom config.active_record.database_resolver can catch ActiveRecord::ReadOnlyError and retry the block against the primary. The app re-raised that error from rescue_from(:all) so the resolver upstream could do its job. On 3.3+ it no longer gets there, so the request 500s where it used to recover, and nothing notices, since the redispatch renders an ordinary 500.
env['grape.exception'] (#2855) is enough to report the exception but not to act on it, because the response is already built by then. Raising a non-StandardError does escape, but it bypasses every intervening rescue => e. Dropping rescue_from :all gives up the catch-all for everything else, and #2737 makes excluding a single class from it an ArgumentError.
#2840 made the same call for the rendering case and added Grape.config.raise_rendering_errors to opt back out. I'd like the equivalent for the handler case:
rescue_from ActiveRecord::ReadOnlyError, propagate: true
Verified the behavior above against 4.0.1. Happy to open a PR if the direction seems right.
- 主要语言
- Ruby
- 星标
- 10k
- 派生
- 1.2k
- 平均合并
- 13 小时 13 分钟
- 30 天内合并 PR
- 115
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby-grape/grape 的其他 Issue
-
feature request you can help
难度 2/5 1-3 小时 新手友好度 64/100
ruby-grape/grape#2487 · 2 条评论 · 2 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 35/100
ruby-grape/grape#2979 · 1 条评论 ·
-
chore
难度 2/5 1-3 小时 新手友好度 30/100
ruby-grape/grape#2562 · 4 条评论 ·
-
feature request
难度 5/5 一周以上 新手友好度 25/100
ruby-grape/grape#2522 · 3 条评论 ·
-
bug?
难度 4/5 3-5 天 新手友好度 48/100
ruby-grape/grape#2473 · 6 条评论 · 1 个 reaction ·
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
hanami/hanami-cli#449 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
resque/resque-scheduler#826 ·
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 75/100