Exception: Lolp::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/lolp/errors.rb

Class Method Summary collapse

Class Method Details

.build_error_message(res = nil) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/lolp/errors.rb', line 26

def build_error_message(res = nil)
  return nil if res.nil?
  message =  "#{res.env.method.to_s.upcase} "
  message << "#{res.env.url}: "
  message << "#{res.status} - "
  message << "#{res.body}" if res.body
  message
end

.from_response(r) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lolp/errors.rb', line 4

def from_response(r)
  if klass = case r.status.to_i
      when 400      then BadRequest
      when 401      then Unauthorized
      when 402      then PaymentRequired
      when 403      then Forbidden
      when 404      then NotFound
      when 406      then NotAcceptable
      when 409      then Conflict
      when 429      then TooManyRequests
      when 422      then UnprocessableEntity
      when 400..499 then ClientError
      when 500      then InternalServerError
      when 501      then NotImplemented
      when 502      then BadGateway
      when 503      then ServiceUnavailable
      when 500..599 then ServerError
      end
    klass.new(build_error_message(r))
  end
end