Sha256: a5d3699d14efd3e4780f640e150a72628a0dab5428bc9f354ce37c0d1f3e5bdd

Contents?: true

Size: 895 Bytes

Versions: 2

Compression:

Stored size: 895 Bytes

Contents

# encoding: utf-8
module Sinatra
  module ErrorHandler
    extend Hexacta

    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)
    end

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

  end

  register ErrorHandler
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sinatra-hexacta-0.3.1 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.0 lib/sinatra/handlers/errors.rb