]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/notes_controller.rb
Add some more tests, better error handling for dates
[rails.git] / app / controllers / notes_controller.rb
index 24d60830c4560d128eb3660ad1cf40ca01e3c23d..690467f0dade10aedc25ede3c8da0d5f69164e01 100644 (file)
@@ -280,18 +280,19 @@ class NotesController < ApplicationController
 
     # Filter by a given start date and an optional end date
     if params[:from]
-      from = Time.parse(params[:from])
-      to = if params[:to]
-             Time.parse(params[:to])
-           else
-             Time.now
-           end
-
-      if from && to
-        @notes = @notes.where("(created_at > '#{from}' AND created_at < '#{to}')")
-      else
+      begin
+        from = Time.parse(params[:from])
+        to = if params[:to]
+               Time.parse(params[:to])
+             else
+               Time.now
+             end
+      rescue ArgumentError
+        # return a more generic error so that everybody knows what is wrong
         raise OSM::APIBadUserInput, "The date is in a wrong format"
       end
+
+      @notes = @notes.where("(created_at > '#{from}' AND created_at < '#{to}')")
     end
 
     # Find the notes we want to return