Exception: Freshly::Error

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = nil) ⇒ Error

Returns a new instance of Error.



32
33
34
35
# File 'lib/freshly/error.rb', line 32

def initialize(response=nil)
  @response = response
  super(build_error_message)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/freshly/error.rb', line 3

def response
  @response
end

Class Method Details

.from_response(response) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/freshly/error.rb', line 5

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 Freshly::BadRequest
              when 401      then Freshly::AuthenticationFailed
              when 403      then Freshly::AccessDenied
              when 404      then Freshly::NotFound
              when 405      then Freshly::MethodNotAllowed
              when 406      then Freshly::NotAcceptable
              when 409      then Freshly::Conflict
              when 415      then Freshly::UnsupportedMediaType
              when 429      then Freshly::RateLimitExceeded
              when 400..499 then Freshly::ClientError
              when 500      then Freshly::InternalServerError
              when 501      then Freshly::NotImplemented
              when 502      then Freshly::BadGateway
              when 503      then Freshly::ServiceUnavailable
              when 500..599 then Freshly::ServerError
              end

    klass.new(response)
  end
end

Instance Method Details

#build_error_messageObject



37
38
39
# File 'lib/freshly/error.rb', line 37

def build_error_message
  "something went wrong"
end