From 9b2791a7ace2adaab91e83dd62d498f60dcb3484 Mon Sep 17 00:00:00 2001 From: Matt Towers Date: Thu, 28 Aug 2014 11:15:08 -0700 Subject: [PATCH] Raise SailThru::ClientError when unable to parse API response If the client fails to parse the response body, then the API is presumed to be malfunctioning and unavailable. Throw an UnavailableError including the actual response body returned. Only return an error body when a parsable response is returned from the API, including a valid error code. e.g. { 'error'=> 9 } Values for 'error' should only ever include valid SailThru error codes returned in a well-formed response body. (http://getstarted.sailthru.com/api/api-response-errors) --- lib/sailthru/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sailthru/client.rb b/lib/sailthru/client.rb index c2a4197..20ee640 100644 --- a/lib/sailthru/client.rb +++ b/lib/sailthru/client.rb @@ -745,7 +745,7 @@ def api_request(action, data, request_type, binary_key = nil) unserialized = JSON.parse(_result) return unserialized ? unserialized : _result rescue JSON::JSONError => e - return {'error' => e} + raise UnavailableError, "Failed to parse response body: #{_result}" end end _result