Skip to content

JSON::ParserError on gateway timeout when proxy responds with HTML #29

@bjeanes

Description

@bjeanes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions