Sha256: a75d5a338d99cbd87893d7a9e52eecd5e9293c7f90a5c6e5ae59b3ee26175bcc

Contents?: true

Size: 749 Bytes

Versions: 28

Compression:

Stored size: 749 Bytes

Contents

module Pliny::Middleware
  class RescueErrors
    def initialize(app, options = {})
      @app = app
      @raise = options[:raise]
    end

    def call(env)
      @app.call(env)
    rescue Pliny::Errors::Error => e
      # blank out this field so that the error is not picked up by Rollbar
      env["sinatra.error"] = nil

      Pliny::Errors::Error.render(e)
    rescue Exception => e
      if @raise
        raise
      else
        dump_error(e, env)
        Pliny::Errors::Error.render(Pliny::Errors::InternalServerError.new)
      end
    end

    private

    # pulled from Sinatra
    def dump_error(e, env)
      message = ["#{e.class} - #{e.message}:", *e.backtrace].join("\n\t")
      env['rack.errors'].puts(message)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
pliny-0.8.1 lib/pliny/middleware/rescue_errors.rb
pliny-0.8.0 lib/pliny/middleware/rescue_errors.rb
pliny-0.7.3 lib/pliny/middleware/rescue_errors.rb
pliny-0.7.2 lib/pliny/middleware/rescue_errors.rb
pliny-0.7.1 lib/pliny/middleware/rescue_errors.rb
pliny-0.7.0 lib/pliny/middleware/rescue_errors.rb
pliny-0.6.3 lib/pliny/middleware/rescue_errors.rb
pliny-0.6.2 lib/pliny/middleware/rescue_errors.rb