~singpolyma/sgx-jmp

1a0e03af118ba863888578286ca4cf801fa2301d — Stephen Paul Weber 1 year, 10 months ago 0cca353
Extract response_status type errors
2 files changed, 12 insertions(+), 1 deletions(-)

M lib/bandwidth_iris_patch.rb
M lib/sip_account.rb
M lib/bandwidth_iris_patch.rb => lib/bandwidth_iris_patch.rb +11 -0
@@ 2,10 2,15 @@

require "ruby-bandwidth-iris"

# rubocop:disable Metrics/AbcSize
module BandwidthIris
	class APIError < StandardError
		attr_reader :code

		def self.for_response_status(description:, error_code:)
			new(description: description, code: error_code)
		end

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


@@ 27,6 32,11 @@ module BandwidthIris
			parsed_body = parse_xml(response.body || "")
			return parsed_body unless response.status >= 400
			raise APIError.new(**parsed_body[:error]) if parsed_body&.key?(:error)

			if parsed_body&.key?(:response_status)
				raise APIError.for_response_status(**parsed_body[:response_status])
			end

			raise APIErrors, parsed_body[:errors] if parsed_body&.key?(:errors)

			raise Errors::GenericError.new(


@@ 35,3 45,4 @@ module BandwidthIris
		end
	end
end
# rubocop:enable Metrics/AbcSize

M lib/sip_account.rb => lib/sip_account.rb +1 -1
@@ 9,7 9,7 @@ require_relative "mn_words"
class SipAccount
	def self.find(name)
		new(BandwidthIris::SipCredential.get(name))
	rescue BandwidthIris::Errors::GenericError # 404
	rescue BandwidthIris::APIError # 404
		New.new(BandwidthIris::SipCredential.new(
			user_name: name,
			realm: CONFIG[:sip][:realm],