Skip to content
This repository was archived by the owner on Sep 5, 2019. It is now read-only.

Commit 91b0817

Browse files
committed
Defined exception classes for 502, 503, and 504 responses
We've received a small number of these responses from Swiftype but, since they were raised as `UnexpectedHTTPException` errors, we weren't able to handle them specifically (for example, by waiting a period of time and then retrying the request). Instead, we could only handle them generically (as unexpected runtime errors).
1 parent 9be4861 commit 91b0817

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/swiftype/exceptions.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ class InvalidCredentials < ClientException; end
66
class BadRequest < ClientException; end
77
class Forbidden < ClientException; end
88
class UnexpectedHTTPException < ClientException; end
9+
10+
class ServerException < StandardError; end
11+
class InternalServerError < ServerException; end
12+
class BadGateway < ServerException; end
13+
class ServiceUnavailable < ServerException; end
14+
class GatewayTimeout < ServerException; end
915
end

lib/swiftype/request.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ def handle_errors(response)
105105
Net::HTTPNotFound => Swiftype::NonExistentRecord,
106106
Net::HTTPConflict => Swiftype::RecordAlreadyExists,
107107
Net::HTTPBadRequest => Swiftype::BadRequest,
108-
Net::HTTPForbidden => Swiftype::Forbidden
108+
Net::HTTPForbidden => Swiftype::Forbidden,
109+
Net::HTTPInternalServerError => Swiftype::InternalServerError,
110+
Net::HTTPBadGateway => Swiftype::BadGateway,
111+
Net::HTTPServiceUnavailable => Swiftype::ServiceUnavailable,
112+
Net::HTTPGatewayTimeOut => Swiftype::GatewayTimeout
109113
}.freeze
110114

111115
def error_message_from_response(response)

0 commit comments

Comments
 (0)