class IronBank::Error
Custom error class for rescuing from all Zuora API errors
Attributes
response[R]
Public Class Methods
from_body(response)
click to toggle source
# File lib/iron_bank/error.rb, line 27 def self.from_body(response) return unless (match = CODE_MATCHER.match(response.body.to_s)) CODE_CLASSES[match.captures.first] end
from_response(response)
click to toggle source
Returns the appropriate IronBank::Error
subclass based on status and response message
# File lib/iron_bank/error.rb, line 8 def self.from_response(response) klass = begin case response.status when 200 then from_body(response) when 400 then IronBank::BadRequestError when 401 then IronBank::UnauthorizedError when 404 then IronBank::NotFoundError when 422 then IronBank::UnprocessableEntityError when 429 then IronBank::TooManyRequestsError when 500 then IronBank::InternalServerError when 400..499 then IronBank::ClientError when 500..599 then IronBank::ServerError else IronBank::Error end end klass&.new(response) end
new(response = nil)
click to toggle source
Calls superclass method
# File lib/iron_bank/error.rb, line 35 def initialize(response = nil) @response = response message = response.is_a?(Faraday::Response) ? message_from_body : response super(message) end
Public Instance Methods
message_from_body()
click to toggle source
# File lib/iron_bank/error.rb, line 43 def message_from_body response && "Body: #{response.body}" end