lib/esp_sdk/client.rb in esp_sdk-1.0.0 vs lib/esp_sdk/client.rb in esp_sdk-1.0.1
- old
+ new
@@ -23,12 +23,15 @@
else
# The rest of our actions will require a payload
fail MissingAttribute, 'Missing required attributes' if payload.blank?
response = RestClient.send(type, url, payload, headers)
end
- rescue RestClient::UnprocessableEntity, RestClient::Unauthorized => e
+ rescue RestClient::Unauthorized => e
+ fail EspSdk::Unauthorized, 'Unauthorized request'
+ rescue RestClient::UnprocessableEntity => e
response = e.response
- check_errors(JSON.load(response.body))
+ body = JSON.load(response.body) if response.body.present?
+ check_errors(JSON.load(body))
end
response
end