Exception: Trell::Error

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

Direct Known Subclasses

ClientError, ServerError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = nil) ⇒ Error

Returns a new instance of Error.



24
25
26
27
# File 'lib/trell/error.rb', line 24

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

Class Method Details

.from_response(response) ⇒ Object



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

def self.from_response(response)
  if klass = case response[:status].to_i
    when 400      then Trell::BadRequest
    when 401      then Trell::Unauthorized
    when 403      then Trell::Forbidden
    when 404      then Trell::NotFound
    when 406      then Trell::NotAcceptable
    when 409      then Trell::Conflict
    when 415      then Trell::UnsupportedMediaType
    when 422      then Trell::UnprocessableEntity
    when 400..499 then Trell::ClientError
    when 500      then Trell::InternalServerError
    when 501      then Trell::NotImplemented
    when 502      then Trell::BadGateway
    when 503      then Trell::ServiceUnavailable
    when 500..599 then Trell::ServerError
    end
    klass.new(response)
  end
end

Instance Method Details

#errorsObject



29
30
31
32
33
34
35
# File 'lib/trell/error.rb', line 29

def errors
  if data && data.is_a?(Hash)
    data[:errors] || []
  else
    []
  end
end