0

我正在根据此处的 API 设置网络挂钩:http: //docs.exceptional.io/api/webhooks/

我看到的问题是发布的数据似乎无效。从日志中:

Started POST "/api/1/services/exceptional/13123123123123123123123123123" for 50.16.14.195 at 2012-11-30 04:27:06 +0000
Processing by ApiV1::Services::ExceptionalController#create as XML
  Parameters: {"{\"error\":{\"id\":110938603,\"title\":\"# (Test-20) \\\"Test message-20\\\"\",\"sub_title\":null,\"app\":{\"id\":17456,\"name\":\"mysite.com\"},\"last_occurrence\":{\"id\":266224025,\"request_method\":null,\"url\":null,\"occurred_at\":\"2012-11-30T04:27:01 00:00\",\"backtrace\":null},\"environment\":null,\"first_occurred_at\":\"2012-11-30T04:27:01 00:00\",\"last_occurred_at\":\"2012-11-30T04:27:01 00:00\",\"url\":\"http://getexl.com/xasdasddsa\"}}"=>nil, "room_token"=>"123123123123213"}
Completed 500 Internal Server Error in 12ms

TypeError (can't convert Array into String):
  app/controllers/api_v1/services/exceptional_controller.rb:20:in `create'
  lib/rack/ie_redirect.rb:19:in `call'

路线:

 match "/exceptional/:room_token" => "exceptional#create"

关于为什么参数被rails破坏以及如何解决的任何想法?谢谢

控制器代码:

类 ApiV1::Services::ExceptionalController < ApiV1::APIController

  def create
    exceptional_exception = JSON.parse(params[:error])
  end

exception_exception 是行是 rb:20

4

1 回答 1

1

似乎出错的是您没有正确构建 URL。例如,实际错误被 rails 解释为键。

通常你会这样写

/api/1/services/exceptional/123123123?error="....<snipped the json>..."

我看到了两种解决方法。恕我直言,解决此问题的最简单方法是编写以下内容:

match '/exceptional/:room_token/:error' => 'exceptional#create'

然后你就不必改变任何东西,它就会工作。

否则,您将不得不正确发布数据,就像我上面所说的那样。

[编辑:评论后]

好的,由于您无法控制正在发生的 POST,请返回原始路线,并在您的控制器中执行以下操作:

def create
  exceptional_exception = JSON.parse(request.body)
end

我认为这应该有效,但不完全确定。我不太明白,通常rails会自动处理好,所以我假设P​​OST本身有问题。

第二条评论:既然您似乎在“重建”异常,为什么不考虑errbit

于 2012-11-30T23:17:47.017 回答