From 976b77e402929902e29b201e8c96a6b74f49da9b Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 31 Jan 2022 10:34:43 -0500 Subject: [PATCH] Sometimes we get a list of errors, such as to LNP --- lib/bandwidth_iris_patch.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/bandwidth_iris_patch.rb b/lib/bandwidth_iris_patch.rb index 5b7f83cb6f2e05ec4ba925847b280d725d1068d5..ed1b1ee617036116ccbc7ce0c6153bb37d9a16be 100644 --- a/lib/bandwidth_iris_patch.rb +++ b/lib/bandwidth_iris_patch.rb @@ -12,12 +12,22 @@ module BandwidthIris end end + class APIErrors < StandardError + attr_reader :errors + + def initialize(errors) + super(errors.map { |e| e[:description] }.join("\n")) + @errors = errors + 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 APIError.new(**parsed_body[:error]) if parsed_body&.key?(:error) + raise APIErrors, parsed_body[:errors] if parsed_body&.key?(:errors) raise Errors::GenericError.new( "", "Http code #{response.status}", response.status