Reputation: 1035
I'm working to setup a web hook based on the API here: http://docs.exceptional.io/api/webhooks/
The issues I'm seeing is the data being posted appears to be invalid. From the logs:
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'
Route:
match "/exceptional/:room_token" => "exceptional#create"
Any ideas on why the params are being corrupted by rails and how to resolve? Thanks
Controller Code:
class ApiV1::Services::ExceptionalController < ApiV1::APIController
def create
exceptional_exception = JSON.parse(params[:error])
end
The exceptional_exception is line is rb:20
Upvotes: 0
Views: 281
Reputation: 50057
What seems to go wrong is that you do not correctly build an URL. E.g. the actual error is interpreted by rails as a key.
Normally you would write it like this
/api/1/services/exceptional/123123123?error="....<snipped the json>..."
I see two ways to solve that. Imho the easiest way to solve this would be to write the following:
match '/exceptional/:room_token/:error' => 'exceptional#create'
Then you will not have to change anything and it will just work.
Otherwise you will have to post the data correctly, like I stated above.
[EDIT: after comment]
Ok, since you have no control whatsoever on the POST that is happening, go back to your original route, and in your controller do the following:
def create
exceptional_exception = JSON.parse(request.body)
end
I think that should work, not entirely sure. I don't quite understand, normally rails would handle that well automatically, so I was assuming there was something wrong with the POST itself.
Second remark: since you are seemingly "rebuilding" exceptional, why not consider errbit.
Upvotes: 1