lib/datasift.rb in datasift-3.7.0 vs lib/datasift.rb in datasift-3.7.1
- old
+ new
@@ -228,12 +228,18 @@
process_client_error(e)
rescue RestClient::ExceptionWithResponse => e
begin
code = e.http_code
body = e.http_body
+ error = nil
if code && body
- error = MultiJson.load(body)
+ begin
+ error = MultiJson.load(body)
+ rescue MultiJson::ParseError
+ # In cases where we receive 502 responses, Nginx may send HTML rather than JSON
+ error = body
+ end
response_on_error = {
:data => nil,
:datasift => {
X_RATELIMIT_LIMIT => e.response.headers[:x_ratelimit_limit],
X_RATELIMIT_REMAINING => e.response.headers[:x_ratelimit_remaining],
@@ -301,9 +307,13 @@
raise UnsupportedMediaTypeError.new(code, body, response)
when 422
raise UnprocessableEntityError.new(code, body, response)
when 429
raise TooManyRequestsError.new(code, body, response)
+ when 500
+ raise InternalServerError.new(code, body, response)
+ when 502
+ raise BadGatewayError.new(code, body, response)
when 503
raise ServiceUnavailableError.new(code, body, response)
when 504
raise GatewayTimeoutError.new(code, body, response)
else