Exception: Postmark::HttpServerError

Inherits:
Error
  • Object
show all
Defined in:
lib/postmark/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code = 500, body = '', parsed_body = {}) ⇒ HttpServerError

Returns a new instance of HttpServerError.



32
33
34
35
36
37
38
39
# File 'lib/postmark/error.rb', line 32

def initialize(status_code = 500, body = '', parsed_body = {})
  self.parsed_body = parsed_body
  self.status_code = status_code.to_i
  self.body = body
  message = parsed_body.fetch('Message', "The Postmark API responded with HTTP status #{status_code}.")

  super(message)
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



13
14
15
# File 'lib/postmark/error.rb', line 13

def body
  @body
end

#parsed_bodyObject Also known as: full_response

Returns the value of attribute parsed_body.



13
14
15
# File 'lib/postmark/error.rb', line 13

def parsed_body
  @parsed_body
end

#status_codeObject

Returns the value of attribute status_code.



13
14
15
# File 'lib/postmark/error.rb', line 13

def status_code
  @status_code
end

Class Method Details

.build(status_code, body) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/postmark/error.rb', line 17

def self.build(status_code, body)
  parsed_body = Postmark::Json.decode(body) rescue {}

  case status_code
  when '401'
    InvalidApiKeyError.new(401, body, parsed_body)
  when '422'
    ApiInputError.build(body, parsed_body)
  when '500'
    InternalServerError.new(500, body, parsed_body)
  else
    UnexpectedHttpResponseError.new(status_code, body, parsed_body)
  end
end

Instance Method Details

#retry?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/postmark/error.rb', line 41

def retry?
  5 == status_code / 100
end