Exception: Badgerkit::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/badgerkit/error.rb

Overview

Custom error class for rescuing from all Badgerkit errors

Direct Known Subclasses

ClientError, ServerError

Class Method Summary collapse

Class Method Details

.from_response(response) ⇒ Badgerkit::Error

Returns the appropriate Badgerkit::Error sublcass based on status and response message

Parameters:

  • response (Hashie::Mash)

    response HTTP response

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/badgerkit/error.rb', line 11

def self.from_response(response)
  status  = response[:status].to_i
  body    = response[:body].to_s
  headers = response[:response_headers]

  if klass =  case status
              when 400      then Octokit::BadRequest
              when 401      then error_for_401(headers)
              when 403      then error_for_403(body)
              when 404      then Octokit::NotFound
              when 406      then Octokit::NotAcceptable
              when 409      then Octokit::Conflict
              when 415      then Octokit::UnsupportedMediaType
              when 422      then Octokit::UnprocessableEntity
              when 400..499 then Octokit::ClientError
              when 500      then Octokit::InternalServerError
              when 501      then Octokit::NotImplemented
              when 502      then Octokit::BadGateway
              when 503      then Octokit::ServiceUnavailable
              when 500..599 then Octokit::ServerError
              end
    klass.new(response)
  end
end