Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

return proper JSON errors on 404

ulferts0669bd92d15b
diff --git a/lib/api/v3/root.rb b/lib/api/v3/root.rb
index 1d2e22b576c..8deeb4b61d6 100644
--- a/lib/api/v3/root.rb
+++ b/lib/api/v3/root.rb
@@ -101,6 +101,12 @@ module API
API::OpenAPI.spec.to_yaml
end
+
+ # Catch all unknown routes (therefore have it at the end of the file)
+ # and return a properly formatted 404 error.
+ route :any, "*path" do
+ raise API::Errors::NotFound
+ end
end
end
end
diff --git a/modules/budgets/spec/requests/api/v3/budgets/budget_resource_spec.rb b/modules/budgets/spec/requests/api/v3/budgets/budget_resource_spec.rb
index 84c1815c169..9e769c15723 100644
--- a/modules/budgets/spec/requests/api/v3/budgets/budget_resource_spec.rb
+++ b/modules/budgets/spec/requests/api/v3/budgets/budget_resource_spec.rb
@@ -61,9 +61,7 @@ RSpec.describe "API v3 Budget resource" do
context "invalid id" do
let(:get_path) { api_v3_paths.budget "bogus" }
- it_behaves_like "param validation error" do
- let(:id) { "bogus" }
- end
+ it_behaves_like "not found"
end
end
diff --git a/modules/costs/spec/requests/api/cost_entries/cost_entry_resource_spec.rb b/modules/costs/spec/requests/api/cost_entries/cost_entry_resource_spec.rb
index 5d7c8175551..094ffd7e747 100644
--- a/modules/costs/spec/requests/api/cost_entries/cost_entry_resource_spec.rb
+++ b/modules/costs/spec/requests/api/cost_entries/cost_entry_resource_spec.rb
@@ -62,9 +62,7 @@ RSpec.describe "API v3 Cost Entry resource" do
context "invalid id" do
let(:get_path) { api_v3_paths.cost_type "bogus" }
- it_behaves_like "param validation error" do
- let(:id) { "bogus" }
- end
+ it_behaves_like "not found"
end
end
diff --git a/modules/costs/spec/requests/api/cost_types/cost_type_resource_spec.rb b/modules/costs/spec/requests/api/cost_types/cost_type_resource_spec.rb
index 763b914271e..f66ce9964af 100644
--- a/modules/costs/spec/requests/api/cost_types/cost_type_resource_spec.rb
+++ b/modules/costs/spec/requests/api/cost_types/cost_type_resource_spec.rb
@@ -67,9 +67,7 @@ RSpec.describe "API v3 Cost Type resource" do
context "invalid id" do
let(:get_path) { api_v3_paths.cost_type "bogus" }
- it_behaves_like "param validation error" do
- let(:id) { "bogus" }
- end
+ it_behaves_like "not found"
end
end
diff --git a/modules/meeting/spec/requests/api/v3/meetings/meetings_resource_spec.rb b/modules/meeting/spec/requests/api/v3/meetings/meetings_resource_spec.rb
index 5d95cc0309f..094095c8939 100644
--- a/modules/meeting/spec/requests/api/v3/meetings/meetings_resource_spec.rb
+++ b/modules/meeting/spec/requests/api/v3/meetings/meetings_resource_spec.rb
@@ -69,9 +69,7 @@ RSpec.describe "API v3 Meeting resource" do
context "when invalid id" do
let(:get_path) { api_v3_paths.budget "bogus" }
- it_behaves_like "param validation error" do
- let(:id) { "bogus" }
- end
+ it_behaves_like "not found"
end
end
diff --git a/spec/features/work_packages/navigation_spec.rb b/spec/features/work_packages/navigation_spec.rb
index 6364eed3f47..3375e552ec3 100644
--- a/spec/features/work_packages/navigation_spec.rb
+++ b/spec/features/work_packages/navigation_spec.rb
@@ -259,7 +259,7 @@ RSpec.describe "Work package navigation", :js, :selenium do
visit "/projects/#{project.identifier}/work_packages?#{url_query}"
wp_table.expect_toast message: "Your view is erroneous and could not be processed.", type: :error
- expect(page).to have_css "li", text: "Bad request: id is invalid"
+ expect(page).to have_css "li", text: "The requested resource could not be found"
end
end
end
diff --git a/spec/requests/api/v3/category_resource_spec.rb b/spec/requests/api/v3/category_resource_spec.rb
index b4ad3aaea0e..b994ec4ce77 100644
--- a/spec/requests/api/v3/category_resource_spec.rb
+++ b/spec/requests/api/v3/category_resource_spec.rb
@@ -100,10 +100,7 @@ RSpec.describe "API v3 Category resource" do
context "invalid priority id" do
let(:get_path) { api_v3_paths.category "bogus" }
- it_behaves_like "param validation error" do
- let(:id) { "bogus" }
- let(:type) { "Category" }
- end
+ it_behaves_like "not found"
end
end
@@ -116,10 +113,7 @@ RSpec.describe "API v3 Category resource" do
get get_path
end
- it_behaves_like "param validation error" do
- let(:id) { "bogus" }
- let(:type) { "Category" }
- end
+ it_behaves_like "not found"
end
end
end
diff --git a/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb b/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb
index 5a56e499fd9..cccdb84c983 100644
--- a/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb
+++ b/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb
@@ -92,10 +92,7 @@ RSpec.describe "API v3 Help texts resource" do
context "invalid type id" do
let(:get_path) { api_v3_paths.type "bogus" }
- it_behaves_like "param validation error" do
- let(:id) { "bogus" }
- let(:type) { "HelpText" }
- end
+ it_behaves_like "not found"
end
context "invisible type id" do
diff --git a/spec/requests/api/v3/priority_resource_spec.rb b/spec/requests/api/v3/priority_resource_spec.rb
index 38547bf77dc..b7f93bdb39b 100644
--- a/spec/requests/api/v3/priority_resource_spec.rb
+++ b/spec/requests/api/v3/priority_resource_spec.rb
@@ -86,10 +86,7 @@ RSpec.describe "API v3 Priority resource" do
context "invalid priority id" do
let(:get_path) { api_v3_paths.priority "bogus" }
- it_behaves_like "param validation error" do
- let(:id) { "bogus" }
- let(:type) { "IssuePriority" }
- end
+ it_behaves_like "not found"
end
end
diff --git a/spec/requests/api/v3/status_resource_spec.rb b/spec/requests/api/v3/status_resource_spec.rb
index 58bbd0bb25f..f9c83ad1941 100644
--- a/spec/requests/api/v3/status_resource_spec.rb
+++ b/spec/requests/api/v3/status_resource_spec.rb
@@ -88,10 +88,7 @@ RSpec.describe "API v3 Status resource" do
context "invalid status id" do
let(:get_path) { api_v3_paths.status "bogus" }
- it_behaves_like "param validation error" do
- let(:id) { "bogus" }
- let(:type) { "Status" }
- end
+ it_behaves_like "not found"
end
end
diff --git a/spec/requests/api/v3/types/type_resource_spec.rb b/spec/requests/api/v3/types/type_resource_spec.rb
index dd21d89a94e..2b6934a37eb 100644
--- a/spec/requests/api/v3/types/type_resource_spec.rb
+++ b/spec/requests/api/v3/types/type_resource_spec.rb
@@ -88,10 +88,7 @@ RSpec.describe "API v3 Type resource" do
context "invalid type id" do
let(:get_path) { api_v3_paths.type "bogus" }
- it_behaves_like "param validation error" do
- let(:id) { "bogus" }
- let(:type) { "Type" }
- end
+ it_behaves_like "not found"
end
end