Class: Sinatra::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/herbert.rb

Overview

By default, if there was an error in Herbert, Sinatra would crash without catching the error and Rack would repond with empty 200 response afterwards. This emulates somewhat consistent behaviour and encapsulation.

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/herbert.rb', line 10

def call(env)
	begin
		call!(env)
	rescue => e
		res = [500,{},[]]
		if (ENV['HERBERT_DEBUG'].to_i==1) || (ENV['RACK_ENV'] =~ /debug/) then
			res[1] = {"Content-Type" => "application/json;charset=utf-8"}
			res[2] = ActiveSupport::JSON.encode({
					:error => {
						:code => 1,
						:message => e.to_s,
						:backtrace => e.backtrace
					}
			
				})
		end
		res
	end
end