From 9f6d8711e767a5a4b57cb05f3ad175e3d675d05b Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 30 Jan 2022 13:39:06 +0000 Subject: [PATCH] Return 406 status code instead of 500 when API request has an invalid format (#34766). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Patch by Felix Schäfer. git-svn-id: http://svn.redmine.org/redmine/trunk@21392 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/views/builders.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/redmine/views/builders.rb b/lib/redmine/views/builders.rb index 6745d0b58..e72610664 100644 --- a/lib/redmine/views/builders.rb +++ b/lib/redmine/views/builders.rb @@ -30,7 +30,9 @@ module Redmine when 'xml', :xml then Builders::Xml.new(request, response) when 'json', :json then Builders::Json.new(request, response) else - raise "No builder for format #{format}" + Rails.logger.error "No builder for format #{format.inspect}" + response.status = 406 + return "We couldn't handle your request, sorry. If you were trying to access the API, make sure to append .json or .xml to your request URL.\n" end if block_given? yield(builder) -- 2.39.5