Module: PublicExceptionExtension

Defined in:
lib/public_exception_extension.rb,
lib/public_exception_extension/railtie.rb,
lib/public_exception_extension/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/public_exception_extension.rb', line 6

def call(env)
  request = ActionDispatch::Request.new(env)
  status  = request.path_info[1..-1].to_i

  begin
    content_type = request.formats.first
  rescue Mime::Type::InvalidMimeType
    content_type = Mime[:text]
  end

  body = { status: status, error: Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500]) }

  render(request, status, content_type, body)
end