This repository has been archived by the owner. It is now read-only.
Permalink
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...
jystewart committed Jul 3, 2012
1 parent a0acb8d commit 375b65b7a88fa2e267dd2a4840ac8f2079590206
Showing with 10 additions and 0 deletions.
  1. +5 −0 app/controllers/application_controller.rb
  2. +5 −0 test/functional/artefacts_controller_test.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
@@ -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

0 comments on commit 375b65b

Please sign in to comment.