~singpolyma/sgx-jmp

ref: 2f7a1b60192a14c86ef9a1f727ea9369cfedc2c6 sgx-jmp/lib/bandwidth_iris_patch.rb -rw-r--r-- 627 bytes
2f7a1b60Stephen Paul Weber Merge branch 'more-tel-selection-coverage' 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

require "ruby-bandwidth-iris"

module BandwidthIris
	class APIError < StandardError
		attr_reader :code

		def initialize(description:, code: nil)
			super(description)
			@code = code
		end
	end

	class Client
		# Expose useful error messages from the API instead of hiding them
		def check_response(response)
			parsed_body = parse_xml(response.body || "")
			return parsed_body unless response.status >= 400
			raise APIError.new(**parsed_body[:error]) if parsed_body.key?(:error)

			raise Errors::GenericError.new(
				"", "Http code #{response.status}", response.status
			)
		end
	end
end