Module: Sinatra::ErrorHandler

Extended by:
Hexacta
Defined in:
lib/sinatra/handlers/errors.rb

Constant Summary

Constants included from Hexacta

Hexacta::GEM_FILE_DIR

Instance Method Summary collapse

Methods included from Hexacta

copy_all_files, copy_dir_structure, copy_file, gem_path, setup_dir

Instance Method Details

#enable_errorsObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/sinatra/handlers/errors.rb', line 6

def enable_errors
  p "Enabling errors..."
  ErrorHandler.setup_dir("/app/views/#{Hexacta::GEM_FILE_DIR}/errors")

  error_template(404)
  error_template(403)
  error_template(500)
  error_template(Sequel::DatabaseDisconnectError)
  error_template(Sequel::DatabaseConnectionError)
end

#error_template(code) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sinatra/handlers/errors.rb', line 17

def error_template(code)
  if code.is_a? Numeric
    template_code = code
  else
    template_code = code.to_s.split('::').last
  end
  ErrorHandler.copy_file("/lib/sinatra/views/errors/#{template_code}.slim","/app/views/#{Hexacta::GEM_FILE_DIR}/errors/#{template_code}.slim")
  error code do
    if code == 500
      title = env['sinatra.error'].message
      message = (["in #{request.url}"] + env['sinatra.error'].backtrace).join(',');
      NotificationSender.instance.send_error(authenticated(User),title,message)
    end
    slim "#{Hexacta::GEM_FILE_DIR}/errors/#{template_code}".to_sym, locals: { :params => params }
  end
end