class Praxis::Responses::InternalServerError

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

Attributes

error[RW]

Public Class Methods

new(error: nil, **opts) click to toggle source
Calls superclass method Praxis::Response::new
# 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

Public Instance Methods

format!(exception = @error) click to toggle source
# File lib/praxis/responses/internal_server_error.rb, line 16
def format!(exception = @error)
  if @error

    if Application.instance.config.praxis.show_exceptions == true
      msg = {
        name: exception.class.name,
        message: exception.message,
        backtrace: exception.backtrace
      }
      msg[:cause] = format!(exception.cause) if exception.cause
    else
      msg = {name: 'InternalServerError', message: "Something bad happened."}
    end

    @body = msg
  end
end