From 2d687b1a39c8318d4efba9300f428f58ed4ad713 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 20 Oct 2021 09:58:39 -0500 Subject: [PATCH] Patch bandwidth-iris to raise useful exceptions --- lib/bandwidth_iris_patch.rb | 27 +++++++++++++++++++++++++++ sgx_jmp.rb | 1 + 2 files changed, 28 insertions(+) create mode 100644 lib/bandwidth_iris_patch.rb diff --git a/lib/bandwidth_iris_patch.rb b/lib/bandwidth_iris_patch.rb new file mode 100644 index 0000000..5b7f83c --- /dev/null +++ b/lib/bandwidth_iris_patch.rb @@ -0,0 +1,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 diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 1284779..91a94dc 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -70,6 +70,7 @@ require_relative "lib/alt_top_up_form" require_relative "lib/add_bitcoin_address" require_relative "lib/backend_sgx" require_relative "lib/bwmsgsv2_repo" +require_relative "lib/bandwidth_iris_patch" require_relative "lib/bandwidth_tn_order" require_relative "lib/btc_sell_prices" require_relative "lib/buy_account_credit_form" -- 2.38.5