diff --git a/lib/intercom/request.rb b/lib/intercom/request.rb index e5e72560..121dfdd9 100644 --- a/lib/intercom/request.rb +++ b/lib/intercom/request.rb @@ -91,7 +91,7 @@ def parse_body(decoded_body, response) rescue JSON::ParserError => _ raise_errors_on_failure(response) end - raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body['type'] == 'error.list' + raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body&['type'] == 'error.list' parsed_body end diff --git a/spec/unit/intercom/request_spec.rb b/spec/unit/intercom/request_spec.rb index 0a2fdf82..3f970502 100644 --- a/spec/unit/intercom/request_spec.rb +++ b/spec/unit/intercom/request_spec.rb @@ -19,4 +19,10 @@ req = Intercom::Request.new('path/', 'GET') req.parse_body(nil, response).must_equal(nil) end + + it 'parse_body returns nil if the decoded_body is "null"' do + response = OpenStruct.new(:code => 500) + req = Intercom::Request.new('path/', 'GET') + req.parse_body('null', response).must_equal(nil) + end end