errship3 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Logan Koester
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,151 @@
1
+ = => errship3
2
+
3
+ The static error pages Rails comes with are nice for getting started - you can't
4
+ break them, no matter what. But without your layout and navigation wrapped around
5
+ them, they create a frustrating trap for your users.
6
+
7
+ The obvious solution is to render your layout into the static file, but what happens
8
+ when you make a change?
9
+
10
+ Worse, what if you run a network of many Rails applications? Should they share one
11
+ error page style? Should they all have their own?
12
+
13
+ You could hire your nephew to keep them all up to date... or you can use Errship3.
14
+
15
+ Errship3 is a Rails 3.1 engine for rendering error pages inside your layout. It supports
16
+ i18n, custom exceptions, and Airbrake (Hoptoad) error tracking.
17
+
18
+ You can also use the flashback method to set an error message and redirect :back safely - if
19
+ a RedirectBackError is raised, the user is dropped off at the nearest error page and given
20
+ the flash message anyway.
21
+
22
+ == Installation
23
+
24
+ Add this to your Gemfile
25
+ gem 'errship3', '~> 3.0.0'
26
+
27
+ Add this to your ApplicationController
28
+ class ApplicationController < ActionController::Base
29
+ include Errship3::Rescuers
30
+ include Errship3::ActiveRecord::Rescuers # or replace 'ActiveRecord' with MongoMapper, or Mongoid
31
+
32
+ Errship3 is ready to go! To test it out in development, you'll need to set
33
+
34
+ config.consider_all_requests_local = false
35
+
36
+ in your config/environments/development.rb file. Just don't forget to change it back
37
+ when you want useful debugging output again instead!
38
+
39
+ Alternatively, simply point your browser to /error or /not_found to get a taste.
40
+
41
+ == Configuration
42
+
43
+ Errship3 renders all error pages with a HTTP status of 200 by default. This is
44
+ done to ensure that the error page is rendered if the web server is configured
45
+ to intercept errors (e.g. proxy_intercept_errors for nginx). If you want to
46
+ have the correct status codes for your errors, add the following to an
47
+ initializer:
48
+
49
+ Errship3.status_code_success = false
50
+
51
+ == I18n
52
+
53
+ If you want to edit the text that is rendered, add the following to your config/locales/*.yml
54
+
55
+ en:
56
+ errship3:
57
+ '404':
58
+ title: 'This page does not exist.'
59
+ description: 'It could have moved, or someone (maybe you!) mistyped the URL.'
60
+ '500':
61
+ title: 'An error has occurred.'
62
+ description: 'This has been reported to our development team. Thank you!'
63
+
64
+ ...and so forth, for any error code you like.
65
+
66
+ == Custom Rescuers
67
+
68
+ If you want errship3 to rescue errors from your own custom exception class, you need
69
+ to add a custom rescuer in your ApplicationController, like so:
70
+
71
+ # Render the 404 page
72
+ rescue_from MyException::SomethingMissing, :with => :render_404_error
73
+
74
+ # Render the 500 page
75
+ rescue_from MyException::SomethingWentWrong, :with => :render_error
76
+
77
+ To customize the error for a particular controller or exception class, add a rescuer
78
+ like this one:
79
+
80
+ rescue_from ActiveRecord::RecordNotFound, :with => ->(e){ render_404_error e, 'monkeys' }
81
+
82
+ and then add your text for that scope to config/locales/*.yml
83
+
84
+ en:
85
+ errship3:
86
+ '404':
87
+ title: 'This page does not exist.'
88
+ description: 'It could have moved, or someone (maybe you!) mistyped the URL.'
89
+ monkeys:
90
+ title: 'They must have escaped'
91
+ description: 'This is now a monkey free zone.'
92
+
93
+
94
+ The following methods are provided:
95
+
96
+ * render_error(exception, errship3_scope = false) # Render the 500 page
97
+ * render_404_error(exception = nil, errship3_scope = false) # Render the 404 page
98
+ * flashback(error_message) # Set the flash and redirect back (RedirectBackError-safe)
99
+
100
+ If Airbrake is installed, every rescuer will report the exception, except for 404.
101
+
102
+ == Changelog
103
+
104
+ 2.2.0
105
+ - Preserve correct status codes by default (Rescuers no longer force a 200 status)
106
+
107
+ 2.1.3
108
+ - Conditionally loading rescuers to check for specific loading ORM
109
+
110
+ 2.1.2
111
+ - Remove explicit Rake version dependency for 1.8.7 compatibility
112
+
113
+ 2.1.1
114
+ - Gemspec update
115
+
116
+ 2.1.0
117
+ - Removes unnecessary dependency on HAML (using ERB instead)
118
+
119
+ 2.0.1
120
+ - Added tests for ActiveRecord, Mongoid and MongoMapper rescuers
121
+ - Fixed Mongoid module
122
+
123
+ 2.0.0
124
+ - Breaks out ORM error handling into submodules. Not backwards compatible.
125
+
126
+ 1.1.0
127
+ - Adds option to specify a custom errship3_scope to use with I18n, allowing each
128
+ rescuer to customize the messages displayed.
129
+
130
+ 1.0.0
131
+ - Upgrade to Rails 3.1 to share error page assets between applications on the asset pipeline.
132
+ - Supports Airbrake as well as HoptoadNotifier
133
+ - Errors are rendered directly into your layout
134
+ - i18n support
135
+ - No default styles - blends seamlessly into its host layout.
136
+
137
+ == Contributing to errship3
138
+
139
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
140
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
141
+ * Fork the project
142
+ * Start a feature/bugfix branch
143
+ * Commit and push until you are happy with your contribution
144
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
145
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
146
+
147
+ == Copyright
148
+
149
+ Copyright (c) 2011 Logan Koester. See LICENSE.txt for
150
+ further details.
151
+
@@ -0,0 +1,7 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ .errship3 {
2
+ }
@@ -0,0 +1,14 @@
1
+ <% content_for :head do %>
2
+ <%= stylesheet_link_tag 'errship3', :media => 'screen, projection' %>
3
+ <% end %>
4
+
5
+ <div class='errship3'>
6
+ <h1 class='error_code'><%= status_code %></h1>
7
+ <% if errship3_scope %>
8
+ <h2><%= t "errship3.#{status_code}.#{errship3_scope}.title" %></h2>
9
+ <p><%= t "errship3.#{status_code}.#{errship3_scope}.description" %></p>
10
+ <% else %>
11
+ <h2><%= t "errship3.#{status_code}.title" %></h2>
12
+ <p><%= t "errship3.#{status_code}.description" %></p>
13
+ <% end %>
14
+ </div>
@@ -0,0 +1,8 @@
1
+ en:
2
+ errship3:
3
+ '404':
4
+ title: 'This page does not exist.'
5
+ description: 'It could have moved, or someone (maybe you!) mistyped the URL.'
6
+ '500':
7
+ title: 'An error has occurred.'
8
+ description: 'This has been reported to our development team. Thank you!'
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ if defined?(Rails::Application)
2
+ Rails.application.routes.draw do
3
+ # Unrecoverable error
4
+ match '/error' => "application#errship3_standard", :as => :error
5
+ match '/not_found' => "application#render_404_error", :as => 'not_found'
6
+
7
+ # Rails currently (until 3.1) ignores rescue_from ActionController::RoutingError, so render 404 manually
8
+ match '*address' => 'application#render_404_error' unless Rails.application.config.consider_all_requests_local
9
+ end
10
+ end
data/lib/errship3.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'rescuers/active_record' if defined?(::ActiveRecord)
2
+ require 'rescuers/mongoid' if defined?(::Mongoid)
3
+ require 'rescuers/mongo_mapper' if defined?(::MongoMapper)
4
+
5
+ module Errship3
6
+ class Engine < ::Rails::Engine
7
+ paths['app/routes'] = 'config/routes.rb'
8
+ paths['app/views'] << 'app/views'
9
+ paths['config/locales'] << 'config/locales'
10
+ end
11
+
12
+ mattr_accessor :status_code_success
13
+ @@status_code_success = true
14
+
15
+ module Rescuers
16
+ def self.included(base)
17
+ unless Rails.application.config.consider_all_requests_local
18
+ base.rescue_from ActionController::RoutingError, :with => :render_404_error
19
+ base.rescue_from ActionController::UnknownController, :with => :render_404_error
20
+ base.rescue_from ::AbstractController::ActionNotFound, :with => :render_404_error
21
+ end
22
+ end
23
+
24
+ def render_error(exception, errship3_scope = false)
25
+ airbrake_class.send(:notify, exception) if airbrake_class
26
+ render :template => '/errship3/standard', :locals => {
27
+ :status_code => 500, :errship3_scope => errship3_scope }, :status => (Errship3.status_code_success ? 200 : 500)
28
+ end
29
+
30
+ def render_404_error(exception = nil, errship3_scope = false)
31
+ render :template => '/errship3/standard', :locals => {
32
+ :status_code => 404, :errship3_scope => errship3_scope }, :status => (Errship3.status_code_success ? 200 : 404)
33
+ end
34
+
35
+ # A blank page with just the layout and flash message, which can be redirected to when
36
+ # all else fails.
37
+ def errship3_standard(errship3_scope = false)
38
+ flash[:error] ||= 'An unknown error has occurred, or you have reached this page by mistake.'
39
+ render :template => '/errship3/standard', :locals => {
40
+ :status_code => 500, :errship3_scope => errship3_scope }
41
+ end
42
+
43
+ # Set the error flash and attempt to redirect back. If RedirectBackError is raised,
44
+ # redirect to error_path instead.
45
+ def flashback(error_message, exception = nil)
46
+ airbrake_class.send(:notify, exception) if airbrake_class
47
+ flash[:error] = error_message
48
+ begin
49
+ redirect_to :back
50
+ rescue ActionController::RedirectBackError
51
+ redirect_to error_path
52
+ end
53
+ end
54
+
55
+ private
56
+ def airbrake_class
57
+ return Airbrake if defined?(Airbrake)
58
+ return HoptoadNotifier if defined?(HoptoadNotifier)
59
+ return false
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,11 @@
1
+ module Errship3
2
+ module ActiveRecord
3
+ module Rescuers
4
+ def self.included(base)
5
+ unless Rails.application.config.consider_all_requests_local
6
+ base.rescue_from ::ActiveRecord::RecordNotFound, :with => :render_404_error
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Errship3
2
+ module MongoMapper
3
+ module Rescuers
4
+ def self.included(base)
5
+ unless Rails.application.config.consider_all_requests_local
6
+ base.rescue_from ::MongoMapper::DocumentNotFound, :with => :render_404_error
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Errship3
2
+ module Mongoid
3
+ module Rescuers
4
+ def self.included(base)
5
+ unless Rails.application.config.consider_all_requests_local
6
+ base.rescue_from ::Mongoid::Errors::DocumentNotFound, :with => :render_404_error
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: errship3
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - nurul@ferdo.us
9
+ - Logan Koester
10
+ - Matthew Wilson
11
+ - David Czarnecki
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2012-12-20 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rake
19
+ requirement: !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: shoulda
35
+ requirement: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ requirement: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 1.0.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: 1.0.0
65
+ - !ruby/object:Gem::Dependency
66
+ name: jeweler
67
+ requirement: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: 1.6.0
73
+ type: :development
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: 1.6.0
81
+ description: Errship3 is a Rails 3.2 engine for rendering error pages inside your
82
+ layout. It supports i18n, custom exceptions, and Airbrake (Hoptoad) error tracking.
83
+ email:
84
+ - Nurul Ferdous
85
+ - lkoester@agoragames.com
86
+ - mwilson@agoragames.com
87
+ - dczarnecki@agoragames.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files:
91
+ - LICENSE.txt
92
+ - README.rdoc
93
+ files:
94
+ - app/assets/javascripts/application.js
95
+ - app/assets/stylesheets/errship3.css
96
+ - app/views/errship3/standard.html.erb
97
+ - config/locales/en.yml
98
+ - config/routes.rb
99
+ - lib/errship3.rb
100
+ - lib/rescuers/active_record.rb
101
+ - lib/rescuers/mongo_mapper.rb
102
+ - lib/rescuers/mongoid.rb
103
+ - LICENSE.txt
104
+ - README.rdoc
105
+ homepage: https://github.com/dynamicguy/errship3
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: 3524080323645867315
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 1.8.23
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Errship3 is a Rails 3.2 engine for rendering error pages inside your layout.
133
+ test_files: []