dblock / strava-ruby-client

A complete Ruby client for the Strava API v3.
https://code.dblock.org/2018/11/27/writing-a-new-strava-api-ruby-client.html
MIT License
97 stars 22 forks source link

Error and status not reported into Strava::Errors::Fault #22

Closed ylecuyer closed 1 year ago

ylecuyer commented 4 years ago

Hi

I have just finished migrating https://github.com/ylecuyer/onmove200 to this gem. overall it went seamlessly except for the error class which doesn't report error and status when doing an upload.

The raw body looks like this:

{:status=>400, :headers=>{"date"=>"Wed, 18 Dec 2019 22:40:08 GMT", "content-type"=>"application/json; charset=utf-8", "transfer-encoding"=>"chunked", "connection"=>"close", "cache-control"=>"no-cache", "via"=>"1.1 linkerd", "x-download-options"=>"noopen", "status"=>"400 Bad Request", "x-ratelimit-limit"=>"600,30000", "x-request-id"=>"c7a703a2-2943-4568-ad0e-4feb5457d982", "referrer-policy"=>"strict-origin-when-cross-origin", "x-frame-options"=>"SAMEORIGIN,DENY", "x-ratelimit-usage"=>"6,35", "x-content-type-options"=>"nosniff", "x-permitted-cross-domain-policies"=>"none", "vary"=>"Origin", "x-xss-protection"=>"1; mode=block"}, :body=>{"id"=>3132246002, "id_str"=>"3132246002", "external_id"=>"ACT_0007.OMD.gpx", "error"=>"ACT_0007.OMD.gpx duplicate of activity 2941970362", "status"=>"There was an error processing your activity.", "activity_id"=>nil}}

But the Strava::Errors::Fault only reports message and errors which don't exist: https://github.com/dblock/strava-ruby-client/blob/master/lib/strava/errors/fault.rb

For the moment I have added both error and status : https://github.com/ylecuyer/strava-ruby-client/blob/master/lib/strava/errors/fault.rb

Do you know if the error message format changed ? Or is it just this endpoint with funky format?

If the fix is worth it, I'll open a PR

dblock commented 4 years ago

We probably need to specialize the error in all the right cases to expose these fields. PR welcome.