rack_errorpage 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rack_errorpage.rb +41 -0
  2. metadata +64 -0
@@ -0,0 +1,41 @@
1
+ require 'time'
2
+ require 'rack/utils'
3
+ require 'rack/mime'
4
+
5
+ module Rack
6
+ # Catches all exceptions, forgets about them, and displays the given html file wth a status of 500
7
+
8
+ class ErrorPage
9
+ attr_reader :filename
10
+
11
+ def initialize(app,filename)
12
+ @app = app
13
+ @filename = filename
14
+ end
15
+
16
+ def call(env)
17
+ status, headers, body =
18
+ begin
19
+ @app.call(env)
20
+ rescue => boom
21
+ render_page
22
+ end
23
+ render_page if env['rack.exception']
24
+ [status, headers, body]
25
+ end
26
+
27
+ private
28
+
29
+ def render_page
30
+ body = [::File.read(@filename)]
31
+ size = Utils.bytesize(body.first)
32
+
33
+ [500, {
34
+ "Last-Modified" => ::File.mtime(@filename).httpdate,
35
+ "Content-Type" => Mime.mime_type(::File.extname(@filename), 'text/plain'),
36
+ "Content-Length" => size.to_s
37
+ }, body]
38
+
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack_errorpage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Michael Gorsuch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-07 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: michael@styledbits.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - lib/rack_errorpage.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/mgorsuch/rack_errorpage
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Simple Rack Middleware catching exceptions and rendering the error page of your choice
63
+ test_files: []
64
+