Module: Rack::MogileFS::Endpoint::Rescues

Included in:
Rack::MogileFS::Endpoint
Defined in:
lib/rack/mogilefs/endpoint/rescues.rb

Overview

Catches some potential MogileFS exceptions and will return sensible HTTP status codes. You can disable with:

Rack::MogileFS::Endpoint.new :debug => true

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rack/mogilefs/endpoint/rescues.rb', line 15

def call(env)
  if @options[:debug]
    super
  else
    with_rescues { super }
  end
end

#initializeObject



10
11
12
13
# File 'lib/rack/mogilefs/endpoint/rescues.rb', line 10

def initialize(*)
  super
  @options[:debug] ||= false
end

#with_rescuesObject



23
24
25
26
27
28
29
30
31
# File 'lib/rack/mogilefs/endpoint/rescues.rb', line 23

def with_rescues
  yield
rescue ::MogileFS::Backend::UnknownKeyError => e
  [ 404, { "Content-Type" => "text/html" }, [e.message] ]
rescue ::MogileFS::UnreachableBackendError => e
  [ 503, { "Content-Type" => "text/html" }, [e.message] ]
rescue ::MogileFS::Error => e
  [ 500, { "Content-Type" => "text/html" }, [e.message] ]
end