Sha256: c11410eb8010b7944d8f639aa01e8cd3b09b411fea763cdf779347f479280ce9

Contents?: true

Size: 486 Bytes

Versions: 4

Compression:

Stored size: 486 Bytes

Contents

require 'rest-core/middleware'

class RestCore::ErrorHandler
  def self.members; [:error_handler]; end
  include RestCore::Middleware

  def call env
    if env[ASYNC]
      app.call(handle(env).merge(ASYNC => lambda{ |response|
        env[ASYNC].call(handle(response))
      }))
    else
      handle(app.call(handle(env)))
    end
  end

  def handle env
    if error_handler(env) && !(env[FAIL] || []).empty?
      error_handler(env).call(env)
    else
      env
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rest-core-1.0.3 lib/rest-core/middleware/error_handler.rb
rest-core-1.0.2 lib/rest-core/middleware/error_handler.rb
rest-core-1.0.1 lib/rest-core/middleware/error_handler.rb
rest-core-1.0.0 lib/rest-core/middleware/error_handler.rb