Exception: FunApi::HTTPException
- Inherits:
-
StandardError
- Object
- StandardError
- FunApi::HTTPException
- Defined in:
- lib/funapi/exceptions.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#initialize(status_code:, detail: nil, headers: nil) ⇒ HTTPException
constructor
A new instance of HTTPException.
- #to_response ⇒ Object
Constructor Details
#initialize(status_code:, detail: nil, headers: nil) ⇒ HTTPException
Returns a new instance of HTTPException.
5 6 7 8 9 10 |
# File 'lib/funapi/exceptions.rb', line 5 def initialize(status_code:, detail: nil, headers: nil) @status_code = status_code @detail = detail || default_detail @headers = headers || {} super(@detail.to_s) end |
Instance Attribute Details
#detail ⇒ Object (readonly)
Returns the value of attribute detail.
3 4 5 |
# File 'lib/funapi/exceptions.rb', line 3 def detail @detail end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/funapi/exceptions.rb', line 3 def headers @headers end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
3 4 5 |
# File 'lib/funapi/exceptions.rb', line 3 def status_code @status_code end |
Instance Method Details
#to_response ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/funapi/exceptions.rb', line 12 def to_response [ status_code, {"content-type" => "application/json"}.merge(headers), [JSON.dump(detail: detail)] ] end |