Exception: Postmark::HttpServerError
- Defined in:
- lib/postmark/error.rb
Direct Known Subclasses
ApiInputError, InternalServerError, InvalidApiKeyError, UnexpectedHttpResponseError
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#parsed_body ⇒ Object
(also: #full_response)
Returns the value of attribute parsed_body.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(status_code = 500, body = '', parsed_body = {}) ⇒ HttpServerError
constructor
A new instance of HttpServerError.
- #retry? ⇒ Boolean
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 = parsed_body.fetch('Message', "The Postmark API responded with HTTP status #{status_code}.") super() end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
13 14 15 |
# File 'lib/postmark/error.rb', line 13 def body @body end |
#parsed_body ⇒ Object 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_code ⇒ Object
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
41 42 43 |
# File 'lib/postmark/error.rb', line 41 def retry? 5 == status_code / 100 end |