Skip to content

Commit f737e33

Browse files
committed
We should return ERROR for JSON errors
1 parent 54f8b51 commit f737e33

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
entitlements-github-plugin (1.2.0)
4+
entitlements-github-plugin (1.2.1)
55
contracts (~> 0.17.0)
66
faraday (~> 2.0)
77
faraday-retry (~> 2.0)

lib/entitlements/service/github.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,10 @@ def graphql_http_post_real(query)
418418
end
419419
{ code: response.code.to_i, data: }
420420
rescue JSON::ParserError => e
421-
# Synthesized 500 below triggers a retry; log at WARN.
422-
Entitlements.logger.warn "#{e.class} #{e.message}: #{response.body.inspect}"
421+
# JSON parse errors mean the API returned something we can't interpret. The
422+
# synthesized 500 below triggers a retry, but the cause is more likely a real
423+
# protocol/server problem than a transient network blip, so log at ERROR.
424+
Entitlements.logger.error "#{e.class} #{e.message}: #{response.body.inspect}"
423425
{ code: 500, data: { "body" => response.body } }
424426
end
425427
rescue => e

spec/unit/entitlements/service/github_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,10 @@
394394
expect(response).to eq(code: 504, data: { "body" => body })
395395
end
396396

397-
it "logs at warn and returns raw text for JSON parsing error" do
397+
it "logs at error and returns raw text for JSON parsing error" do
398398
answer = "mor chicken mor rewardz!"
399399
stub_request(:post, "https://github.fake/api/v3/graphql").to_return(status: 200, body: answer)
400-
expect(logger).to receive(:warn).with("JSON::ParserError unexpected character: 'mor' at line 1 column 1: \"mor chicken mor rewardz!\"")
400+
expect(logger).to receive(:error).with("JSON::ParserError unexpected character: 'mor' at line 1 column 1: \"mor chicken mor rewardz!\"")
401401
response = subject.send(:graphql_http_post_real, "nonsense")
402402
expect(response).to eq(code: 500, data: { "body" => "mor chicken mor rewardz!" })
403403
end

0 commit comments

Comments
 (0)