]> git.openstreetmap.org Git - rails.git/commitdiff
JSON: return HTTP 406 for unsupported formats
authormmd-osm <mmd.osm@gmail.com>
Wed, 22 Jan 2020 21:33:30 +0000 (22:33 +0100)
committermmd-osm <mmd.osm@gmail.com>
Wed, 22 Jan 2020 21:33:30 +0000 (22:33 +0100)
app/controllers/application_controller.rb
test/controllers/api/map_controller_test.rb

index bee5e8169a4709d05f5d36ead2c6924a03f2db6a..f419460ee77bc97762ad6c9bc230d0718cb88c9b 100644 (file)
@@ -185,6 +185,8 @@ class ApplicationController < ActionController::Base
 
   def api_call_handle_error
     yield
 
   def api_call_handle_error
     yield
+  rescue ActionController::UnknownFormat
+    head :not_acceptable
   rescue ActiveRecord::RecordNotFound => e
     head :not_found
   rescue LibXML::XML::Error, ArgumentError => e
   rescue ActiveRecord::RecordNotFound => e
     head :not_found
   rescue LibXML::XML::Error, ArgumentError => e
index d5cbfb4efadd0e9b24ccd8ad87dc7f3b9a78f945..9f14cc7fd8dbf8cd5512766a214105c2ce1a3ebb 100644 (file)
@@ -95,16 +95,15 @@ module Api
       assert_response :success, "Expected success with the map call"
       assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
 
       assert_response :success, "Expected success with the map call"
       assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
 
-      # text/json is in invalid format, ActionController::UnknownFormat error is expected
+      # text/json is in invalid format, return HTTP 406 Not acceptable
       http_accept_format("text/json")
       get :index, :params => { :bbox => bbox }
       http_accept_format("text/json")
       get :index, :params => { :bbox => bbox }
-      assert_response :internal_server_error, "text/json should fail"
+      assert_response :not_acceptable, "text/json should fail"
 
 
-      # image/jpeg is a format which we don't support, ActionController::UnknownFormat error is expected
-      # HTTP 406 Not acceptable would be the correct response error code. That's outside of our control though.
+      # image/jpeg is a format which we don't support, return HTTP 406 Not acceptable
       http_accept_format("image/jpeg")
       get :index, :params => { :bbox => bbox }
       http_accept_format("image/jpeg")
       get :index, :params => { :bbox => bbox }
-      assert_response :internal_server_error, "text/json should fail"
+      assert_response :not_acceptable, "text/json should fail"
     end
 
     # -------------------------------------
     end
 
     # -------------------------------------