我使用的是grape,我想访问rescue_from中的请求参数:
class API < Grape::API
rescue_from Grape::Exceptions::ValidationErrors do |e|
rack_response({
end
...我该怎么做呢?
发布于 2014-09-02 17:34:30
我设法做到了这一点:
rescue_from :all do |e|
req = Rack::Request.new(env)
ApiCallAudits.create data: {input_params: req.params.as_json}, backtrace: $!.to_s, status: :error
end发布于 2014-09-01 22:56:40
您可以尝试如下所示:
rescue_from Grape::Exceptions::ValidationErrors do |e|
env['api.endpoint'].helper_method
endhttps://github.com/intridea/grape/issues/438应该可以在helper中使用,但是我不确定这个技巧是否正确。
发布于 2021-03-09 14:23:25
一个更新的答案,以防有人还在想这个问题:
rescue_from Grape::Exceptions::ValidationErrors do |e|
env['grape.request'].params
endhttps://stackoverflow.com/questions/25608098
复制相似问题