Class: Praxis::Responses::InternalServerError

Inherits:
Praxis::Response show all
Defined in:
lib/praxis/responses/internal_server_error.rb

Overview

A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

Instance Attribute Summary collapse

Attributes inherited from Praxis::Response

#body, #headers, #name, #parts, #request, #status

Instance Method Summary collapse

Methods inherited from Praxis::Response

#add_part, #encode!, #finish, #handle, inherited, #response_name, #validate

Constructor Details

#initialize(error: nil, **opts) ⇒ InternalServerError

Returns a new instance of InternalServerError.



10
11
12
13
14
# File 'lib/praxis/responses/internal_server_error.rb', line 10

def initialize(error: nil, **opts)
  super(**opts)
  @headers['Content-Type'] = 'application/json' #TODO: might want an error mediatype
  @error = error
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



8
9
10
# File 'lib/praxis/responses/internal_server_error.rb', line 8

def error
  @error
end

Instance Method Details

#format!(exception = @error) ⇒ Object

_exception(exception)



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/praxis/responses/internal_server_error.rb', line 16

def format!(exception = @error) #_exception(exception)
  if @error
    msg = {
      name: exception.class.name,
      message: exception.message,
      backtrace: exception.backtrace
    }
    msg[:cause] = format!(exception.cause) if exception.cause
    @body = msg
  end
end