lib/tops_connect/client.rb in tops_connect-0.4.2.1 vs lib/tops_connect/client.rb in tops_connect-0.4.3
- old
+ new
@@ -1,9 +1,10 @@
# frozen_string_literal: true
module TopsConnect
class Client
include HTTParty
+ include TopsConnect::Errors
include TopsConnect::Communities
include TopsConnect::Owners
include TopsConnect::Properties
attr_reader :community_id, :community_api_key
@@ -45,37 +46,18 @@
when 404
raise TopsConnect::NotFoundError, response
when 400..499
raise TopsConnect::ClientError, response
when 500..599
+ message = response.parsed_response&.dig('Message') || ''
+
+ # These errors can largely be ignored - it's not our fault
+ raise TopsConnect::TimeoutError, response if message['Timeout expired']
+
raise TopsConnect::InternalError, response
else
# As far as I'm aware, Tops does not return 100 - 199 or 201 - 399.
raise TopsConnect::ApiError, response
end
end
- end
-
- class ApiError < ::RuntimeError
- def initialize(response)
- @response = response
- end
-
- def to_s
- format(
- '%{code}: %{message} (%{uri})',
- code: @response.code,
- message: @response.parsed_response&.dig('Message'),
- uri: @response.request.last_uri.to_s
- )
- end
- end
-
- class ClientError < ApiError
- end
-
- class NotFoundError < ClientError
- end
-
- class InternalError < ApiError
end
end