Skip to content

Commit 33fff32

Browse files
authored
raise an explicit exception when response does not include a JSON body (#520)
1 parent 27ebf6b commit 33fff32

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/nylas/handler/http_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def default_headers
119119
def parse_response(response)
120120
return response if response.is_a?(Enumerable)
121121

122-
Yajl::Parser.new(symbolize_names: true).parse(response)
122+
Yajl::Parser.new(symbolize_names: true).parse(response) || raise(Nylas::JsonParseError)
123123
rescue Yajl::ParseError
124124
raise Nylas::JsonParseError
125125
end

spec/nylas/handler/http_client_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class TestHttpClient
4646

4747
expect { http_client.send(:parse_response, response) }.to raise_error(Nylas::JsonParseError)
4848
end
49+
50+
it "raises an error if the response is empty" do
51+
response = ""
52+
53+
expect { http_client.send(:parse_response, response) }.to raise_error(Nylas::JsonParseError)
54+
end
4955
end
5056

5157
describe "#build_request" do

0 commit comments

Comments
 (0)