Exception: Nusii::NusiiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/nusii/nusii_error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, body, reason_phrase) ⇒ NusiiError

Returns a new instance of NusiiError.



5
6
7
8
9
# File 'lib/nusii/nusii_error.rb', line 5

def initialize status, body, reason_phrase
  @status        = status
  @body          = body
  @reason_phrase = reason_phrase
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/nusii/nusii_error.rb', line 3

def body
  @body
end

#reason_phraseObject (readonly)

Returns the value of attribute reason_phrase.



3
4
5
# File 'lib/nusii/nusii_error.rb', line 3

def reason_phrase
  @reason_phrase
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/nusii/nusii_error.rb', line 3

def status
  @status
end

Class Method Details

.error_for(status) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nusii/nusii_error.rb', line 20

def self.error_for status
  case status
  when 400 then BadRequestError
  when 401 then UnauthorizedError
  when 403 then ForbiddenError
  when 404 then NotFoundError
  when 405 then MethodNotAllowedError
  when 406 then NotAcceptableError
  when 410 then GoneError
  when 429 then TooManyRequestsError
  when 500 then IntervalServerError
  when 503 then ServiceUnavailableError
  else NusiiError
  end
end

Instance Method Details

#messageObject



16
17
18
# File 'lib/nusii/nusii_error.rb', line 16

def message
  @message ||= body.presence || reason_phrase.presence
end

#to_sObject



11
12
13
14
# File 'lib/nusii/nusii_error.rb', line 11

def to_s
  message_text = message.present? ? "\nMessage: #{message}" : ''
  "Status: #{status}#{message_text}"
end