Change summary
lib/bandwidth_iris_patch.rb | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
Detailed changes
@@ -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