Skip to content

Commit e450f85

Browse files
committed
[feature] handle 504 response
Default handling for unexpected response bodies ([here](#492)) has revealed an unhandled 504 response from intercom. Example message from UnexpectedResponseError: ``` Intercom::UnexpectedResponseError, Expected a JSON response body. Instead got '<html> <head><title>504 Gateway Time-out</title></head> <body bgcolor="white"> <center><h1>504 Gateway Time-out</h1></center> </body> </html> ' with status code '504'. ```
1 parent 65a82a2 commit e450f85

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

lib/intercom/errors.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class ServerError < IntercomError; end
4242
# Raised when we have bad gateway errors.
4343
class BadGatewayError < IntercomError; end
4444

45+
# Raised when we have gateway timeout errors.
46+
class GatewayTimeoutError < IntercomError; end
47+
4548
# Raised when we experience a socket read timeout
4649
class ServiceUnavailableError < IntercomError; end
4750

lib/intercom/request.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def execute(target_base_url=nil, username:, secret: nil, read_timeout: 90, open_
168168
raise Intercom::BadGatewayError.new('Bad Gateway Error')
169169
elsif code == 503
170170
raise Intercom::ServiceUnavailableError.new('Service Unavailable')
171+
elsif code == 504
172+
raise Intercom::GatewayTimeoutError.new('Gateway Timeout')
171173
end
172174
end
173175

spec/unit/intercom/request_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ def execute!
109109

110110
expect { execute! }.must_raise(Intercom::RateLimitExceeded)
111111
end
112+
113+
it 'raises a GatewayTimeoutError error when the response code is 504' do
114+
stub_request(:any, uri).to_return(
115+
status: 504,
116+
body: '<html> <head><title>504 Gateway Time-out</title></head> <body bgcolor="white"> <center><h1>504 Gateway Time-out</h1></center> </body> </html>'
117+
)
118+
119+
expect { execute! }.must_raise(Intercom::GatewayTimeoutError)
120+
end
112121
end
113122

114123
describe "application error handling" do

0 commit comments

Comments
 (0)