class Github::Error::ServiceError
Constants
- MIN_BODY_LENGTH
Attributes
body[R]
http_headers[R]
status[R]
Public Class Methods
errors()
click to toggle source
# File lib/github_api/error/service_error.rb, line 53 def self.errors @errors ||= Hash[ descendants.map { |klass| [klass.new({}).http_status_code, klass] } ] end
http_status_code(code)
click to toggle source
# File lib/github_api/error/service_error.rb, line 49 def self.http_status_code(code) define_method(:http_status_code) { code } end
new(response)
click to toggle source
Calls superclass method
Github::Error::GithubError.new
# File lib/github_api/error/service_error.rb, line 12 def initialize(response) @http_headers = response[:response_headers] @body = parse_body(response[:body]) @status = response[:status] super(create_message(response)) end
Public Instance Methods
create_message(response)
click to toggle source
# File lib/github_api/error/service_error.rb, line 20 def create_message(response) "#{response[:method].to_s.upcase} #{response[:url]}: #{@status} #{@body}" end
decode_body(body)
click to toggle source
# File lib/github_api/error/service_error.rb, line 24 def decode_body(body) if body.respond_to?(:to_str) && body.length >= MIN_BODY_LENGTH JSON.parse(body, symbolize_names: true) else body end end
parse_body(body)
click to toggle source
# File lib/github_api/error/service_error.rb, line 32 def parse_body(body) body = decode_body(body) return '' if body.nil? || body.empty? if body[:error] body[:error] elsif body[:errors] error = Array(body[:errors]).first error.is_a?(Hash) ? error[:message] : error elsif body[:message] body[:message] else '' end end