class OpConnect::Error
Public Class Methods
from_response(response)
click to toggle source
# File lib/op_connect/error.rb, line 4 def from_response(response) status = response.status if (klass = case status when 400 then OpConnect::BadRequest when 401 then OpConnect::Unauthorized when 403 then OpConnect::Forbidden when 404 then OpConnect::NotFound when 413 then OpConnect::PayloadTooLarge when 400..499 then OpConnect::ClientError when 500 then OpConnect::InternalServerError when 503 then OpConnect::ServiceUnavailable when 500..599 then OpConnect::ServerError end) klass.new(response) end end
new(response = nil)
click to toggle source
Calls superclass method
# File lib/op_connect/error.rb, line 23 def initialize(response = nil) @response = response super(build_error_message) end
Private Instance Methods
build_error_message()
click to toggle source
# File lib/op_connect/error.rb, line 30 def build_error_message return nil if @response.nil? message = "#{@response.method.to_s.upcase} " message << "#{@response.url}: " message << "#{@response.status} - " message << @response.body["message"].to_s if @response.body["message"] message << "\n\n#{@response.body}\n\n" message end