Skip to content

Commit

Permalink
add configuration option for status codes; addresses issue #11
Browse files Browse the repository at this point in the history
  • Loading branch information
fschwahn committed Nov 2, 2011
1 parent 0f77b4a commit 579b607
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ when you want useful debugging output again instead!

Alternatively, simply point your browser to /error or /not_found to get a taste.

== Configuration

Errship renders all error pages with a HTTP status of 200 by default. This is
done to ensure that the error page is rendered if the web server is configured
to intercept errors (e.g. proxy_intercept_errors for nginx). If you want to
have the correct status codes for your errors, add the following to an
initializer:

Errship.status_code_success = false

== I18n

If you want to edit the text that is rendered, add the following to your config/locales/*.yml
Expand Down
7 changes: 5 additions & 2 deletions lib/errship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class Engine < ::Rails::Engine
paths['app/views'] << 'app/views'
paths['config/locales'] << 'config/locales'
end

mattr_accessor :status_code_success
@@status_code_success = true

module Rescuers
def self.included(base)
Expand All @@ -21,12 +24,12 @@ def self.included(base)
def render_error(exception, errship_scope = false)
airbrake_class.send(:notify, exception) if airbrake_class
render :template => '/errship/standard', :locals => {
:status_code => 500, :errship_scope => errship_scope }
:status_code => 500, :errship_scope => errship_scope }, :status => (Errship.status_code_success ? 200 : 500)
end

def render_404_error(exception = nil, errship_scope = false)
render :template => '/errship/standard', :locals => {
:status_code => 404, :errship_scope => errship_scope }
:status_code => 404, :errship_scope => errship_scope }, :status => (Errship.status_code_success ? 200 : 404)
end

# A blank page with just the layout and flash message, which can be redirected to when
Expand Down
8 changes: 8 additions & 0 deletions test/errship_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@ class ErrshipIntegrationTest < ActionController::IntegrationTest
test "/any_nonexistant_route is routed to errship's 404 page" do
get '/any_nonexistant_route'
assert_routing '/error', { :controller => 'application', :action => 'errship_standard' }
assert_response :success
end

test "errship's 404 page has a 404 status code if configured so" do
Errship.status_code_success = false
get '/any_nonexistant_route'
assert_response :missing
end

end

0 comments on commit 579b607

Please sign in to comment.