Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Return the correct status code when a NotFound is raised

  • Loading branch information...
commit eefc3d3b20c14ac992d598e5ef2bc4a66d495f2b 1 parent 95aca76
Ben Bleything bleything authored rtomayko committed
Showing with 16 additions and 1 deletion.
  1. +3 −0  ChangeLog
  2. +2 −1  lib/sinatra.rb
  3. +11 −0 test/application_test.rb
3  ChangeLog
View
@@ -6,6 +6,9 @@
environment when given. Thin sets this when started with
the -e argument.
+ * BUG: raising Sinatra::NotFound resulted in a 500 response
+ code instead of 404.
+
* BUG: use_in_file_templates! failes with CR/LF (#45)
* BUG: Sinatra detects the app file and root path when run under
3  lib/sinatra.rb
View
@@ -1271,7 +1271,8 @@ def dispatch(env)
request.env['rack.errors'] << msg
request.env['sinatra.error'] = e
- context.status(500)
+ status = e.class.code rescue 500
+ context.status(status)
raise if options.raise_errors && e.class != NotFound
result = (errors[e.class] || errors[ServerError]).invoke(request)
returned =
11 test/application_test.rb
View
@@ -96,6 +96,17 @@ def each
end
+ specify "404 if NotFound is raised" do
+
+ get '/' do
+ raise Sinatra::NotFound
+ end
+
+ get_it '/'
+ should.be.not_found
+
+ end
+
end
context "Application#configure blocks" do
Please sign in to comment.
Something went wrong with that request. Please try again.