Sha256: 6115cb33e3b8f9b50dd5b0dceefe958ee627b820f14981ec0c78691f4fdc358a

Contents?: true

Size: 897 Bytes

Versions: 15

Compression:

Stored size: 897 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.copy_file("/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

15 entries across 15 versions & 1 rubygems

Version Path
sinatra-hexacta-0.3.16 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.15 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.14 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.13 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.12 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.11 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.10 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.9 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.8 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.7 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.6 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.5 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.4 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.3 lib/sinatra/handlers/errors.rb
sinatra-hexacta-0.3.2 lib/sinatra/handlers/errors.rb