Class: Rack::ErrorHandling

Inherits:
Object
  • Object
show all
Defined in:
lib/unicorn-cuba-base/rack/error_handling.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, &block) ⇒ ErrorHandling

Returns a new instance of ErrorHandling.



3
4
5
# File 'lib/unicorn-cuba-base/rack/error_handling.rb', line 3

def initialize(app, &block)
	@app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/unicorn-cuba-base/rack/error_handling.rb', line 7

def call(env)
	# save original env
	orig_env = env.dup
	begin
		return @app.call(env)
	rescue => error
		begin
			# reset env to original since it could have been changed
			env.clear
			env.merge!(orig_env)

			# set error so app can handle it
			env["app.error"] = error

			return @app.call(env)
		rescue
			raise
		end
	end
end