【发布时间】:2014-10-25 19:35:08
【问题描述】:
我正在使用葡萄,我想访问rescue_from中的请求参数:
class API < Grape::API
rescue_from Grape::Exceptions::ValidationErrors do |e|
rack_response({
end
...
我该怎么做?
【问题讨论】:
标签: ruby-on-rails rack grape
我正在使用葡萄,我想访问rescue_from中的请求参数:
class API < Grape::API
rescue_from Grape::Exceptions::ValidationErrors do |e|
rack_response({
end
...
我该怎么做?
【问题讨论】:
标签: ruby-on-rails rack grape
我设法做到了:
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
【讨论】:
你可以试试这样的:
rescue_from Grape::Exceptions::ValidationErrors do |e|
env['api.endpoint'].helper_method
end
婴儿车应该可以在 helper 中使用,但我不确定这个技巧 https://github.com/intridea/grape/issues/438
【讨论】:
如果有人仍然对此感到疑惑,请提供更新的答案:
rescue_from Grape::Exceptions::ValidationErrors do |e|
env['grape.request'].params
end
【讨论】: