Class: Sinatra::Base
- Inherits:
-
Object
- Object
- Sinatra::Base
- Defined in:
- lib/herbert.rb
Overview
FIXME this is ugly By default, if there were an error in Herbert, Sinatra would crash without catching the error and Rack would respond with empty 200 response afterwards. This emulates somewhat consistent behaviour and encapsulation.
Instance Method Summary collapse
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/herbert.rb', line 11 def call(env) begin dup.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 |