Sha256: e0d3038ba48817895cf64ff371c5682155a8eb9eaeef719c1af88d73f43cfb73

Contents?: true

Size: 1.11 KB

Versions: 27

Compression:

Stored size: 1.11 KB

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)
      error_template(Sequel::DatabaseDisconnectError)
      error_template(Sequel::DatabaseConnectionError)
    end

    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

  end

  register ErrorHandler
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
sinatra-hexacta-1.7.20 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.19 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.18 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.17 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.16 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.15 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.14 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.13 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.12 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.11 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.10 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.9 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.8 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.7 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.6 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.5 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.4 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.3 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.2 lib/sinatra/handlers/errors.rb
sinatra-hexacta-1.7.0 lib/sinatra/handlers/errors.rb