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.16.3 lib/pliny/middleware/rescue_errors.rb
pliny-0.16.2 lib/pliny/middleware/rescue_errors.rb
pliny-0.16.1 lib/pliny/middleware/rescue_errors.rb
pliny-0.16.0 lib/pliny/middleware/rescue_errors.rb
pliny-0.15.1 lib/pliny/middleware/rescue_errors.rb
pliny-0.15.0 lib/pliny/middleware/rescue_errors.rb
pliny-0.14.2 lib/pliny/middleware/rescue_errors.rb
pliny-0.14.1 lib/pliny/middleware/rescue_errors.rb
pliny-0.14.0 lib/pliny/middleware/rescue_errors.rb
pliny-0.13.1 lib/pliny/middleware/rescue_errors.rb
pliny-0.13.0 lib/pliny/middleware/rescue_errors.rb
pliny-0.12.0 lib/pliny/middleware/rescue_errors.rb
pliny-0.11.2 lib/pliny/middleware/rescue_errors.rb
pliny-0.11.1 lib/pliny/middleware/rescue_errors.rb
pliny-0.11.0 lib/pliny/middleware/rescue_errors.rb
pliny-0.10.0 lib/pliny/middleware/rescue_errors.rb
pliny-0.9.2 lib/pliny/middleware/rescue_errors.rb
pliny-0.9.1 lib/pliny/middleware/rescue_errors.rb
pliny-0.9.0 lib/pliny/middleware/rescue_errors.rb
pliny-0.8.2 lib/pliny/middleware/rescue_errors.rb