Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Mongoid::Errors::DocumentNotFound will now trigger a 404 not a 500

Should save us lots of email... If an artefact isn't found we'll now see a 404 rather than getting an exception alert.
  • Loading branch information...
commit 375b65b7a88fa2e267dd2a4840ac8f2079590206 1 parent a0acb8d
@jystewart jystewart authored
View
5 app/controllers/application_controller.rb
@@ -3,5 +3,10 @@ class ApplicationController < ActionController::Base
before_filter :authenticate_user!
+ rescue_from Mongoid::Errors::DocumentNotFound, with: :record_not_found
+
+ def record_not_found
+ render text: "404 Not Found", status: 404
+ end
# protect_from_forgery
end
View
5 test/functional/artefacts_controller_test.rb
@@ -79,6 +79,11 @@ class ArtefactsControllerTest < ActionController::TestCase
assert_equal artefact.section, parsed['section']
end
+ should "return 404 if the artefact's not found" do
+ get :show, id: 'bad-slug', format: :json
+ assert_equal 404, response.code.to_i
+ end
+
end
context "PUT /artefacts/:id" do
Please sign in to comment.
Something went wrong with that request. Please try again.