lib/jellyfish.rb in jellyfish-1.0.0 vs lib/jellyfish.rb in jellyfish-1.0.1

- old
+ new

@@ -8,10 +8,11 @@ autoload :MultiActions , 'jellyfish/multi_actions' autoload :NormalizedParams, 'jellyfish/normalized_params' autoload :NormalizedPath , 'jellyfish/normalized_path' autoload :ChunkedBody, 'jellyfish/chunked_body' + autoload :WebSocket , 'jellyfish/websocket' Cascade = Object.new GetValue = Object.new class Response < RuntimeError @@ -127,11 +128,13 @@ # ----------------------------------------------------------------- module DSL def routes ; @routes ||= {}; end def handlers; @handlers ||= {}; end - def handle exception, &block; handlers[exception] = block; end + def handle *exceptions, &block + exceptions.each{ |exp| handlers[exp] = block } + end def handle_exceptions value=GetValue if value == GetValue @handle_exceptions else @handle_exceptions = value @@ -185,11 +188,16 @@ case res = catch(:halt){ ctrl.call(env) } when Cascade cascade(ctrl, env) when Response handle(ctrl, res, env['rack.errors']) - else # make sure we return rack triple - res || ctrl.block_call(nil, lambda{|_|_}) + when Array + res + when NilClass # make sure we return rack triple + ctrl.block_call(nil, lambda{|_|_}) + else + raise TypeError.new("Expect the response to be a Jellyfish::Response" \ + " or Rack triple (Array), but got: #{res.inspect}") end rescue => e handle(ctrl, e, env['rack.errors']) end