The root cause of this is because, in multiple places, the client tries to decode the body before checking the response code and appears to assume that any non-200 will comply with the shape {"error": "..."} which is not the case across the board.
|
data = JSON.parse(response.body) |
|
if response.status != 200 |
|
if response.body.to_s != '' && response.body.to_s != ' ' |
|
data = JSON.parse(response.body) |
|
end |
|
return true if response.status == 200 |
|
data = JSON.parse(response.body) |
|
if response.status != 200 |
|
raise "Can't find object (#{self.class.name}): #{data['error']}" |
|
end |
|
attributes = JSON.parse(response.body) |
|
return attributes if response.status == 201 |
|
attributes = JSON.parse(response.body) |
|
|
|
return attributes if response.status == 200 |
|
data = JSON.parse(response.body) |
|
if response.status != 200 |
|
raise "Can't get articles (#{self.class.name}): #{data['error']}" |
|
end |
It would be preferable to check the response code first and extract the data["error"] in a failsafe way (e.g. by rescuing on the JSON::ParserError
The root cause of this is because, in multiple places, the client tries to decode the body before checking the response code and appears to assume that any non-200 will comply with the shape
{"error": "..."}which is not the case across the board.zammad-api-client-ruby/lib/zammad_api/list_base.rb
Lines 68 to 69 in d897889
zammad-api-client-ruby/lib/zammad_api/resources/base.rb
Lines 42 to 45 in d897889
zammad-api-client-ruby/lib/zammad_api/resources/base.rb
Lines 77 to 80 in d897889
zammad-api-client-ruby/lib/zammad_api/resources/base.rb
Lines 107 to 108 in d897889
zammad-api-client-ruby/lib/zammad_api/resources/base.rb
Lines 118 to 120 in d897889
zammad-api-client-ruby/lib/zammad_api/resources/ticket.rb
Lines 6 to 9 in d897889
It would be preferable to check the response code first and extract the
data["error"]in a failsafe way (e.g. by rescuing on theJSON::ParserError