Exception: FunApi::HTTPException

Inherits:
StandardError
  • Object
show all
Defined in:
lib/funapi/exceptions.rb

Direct Known Subclasses

ValidationError

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#detailObject (readonly)

Returns the value of attribute detail.



3
4
5
# File 'lib/funapi/exceptions.rb', line 3

def detail
  @detail
end

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/funapi/exceptions.rb', line 3

def headers
  @headers
end

#status_codeObject (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_responseObject



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