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

Correctly wrap one error in invalid query, using create_if_many

Oliver Günther60c32f1982be
diff --git a/lib/api/v3/notifications/notifications_api.rb b/lib/api/v3/notifications/notifications_api.rb
index cdf86481c8c..937b6dfffb1 100644
--- a/lib/api/v3/notifications/notifications_api.rb
+++ b/lib/api/v3/notifications/notifications_api.rb
@@ -55,7 +55,11 @@ module API
notification_query.results.update_all({ updated_at: Time.zone.now }.merge(attributes))
status 204
else
- raise ::API::Errors::InvalidQuery.new(notification_query.errors.full_messages)
+ api_errors = notification_query.errors.full_messages.map do |message|
+ ::API::Errors::InvalidQuery.new(message)
+ end
+
+ raise ::API::Errors::MultipleErrors.create_if_many api_errors
end
end
end
diff --git a/lib/api/v3/queries/helpers/query_representer_response.rb b/lib/api/v3/queries/helpers/query_representer_response.rb
index 8bb5c9339d7..cab6a04c159 100644
--- a/lib/api/v3/queries/helpers/query_representer_response.rb
+++ b/lib/api/v3/queries/helpers/query_representer_response.rb
@@ -43,7 +43,11 @@ module API
embed_links: true,
params:)
else
- raise ::API::Errors::InvalidQuery.new(representer.errors.full_messages)
+ api_errors = query.errors.full_messages.map do |message|
+ ::API::Errors::InvalidQuery.new(message)
+ end
+
+ raise ::API::Errors::MultipleErrors.create_if_many api_errors
end
end
end
diff --git a/lib/api/v3/utilities/endpoints/index.rb b/lib/api/v3/utilities/endpoints/index.rb
index 6bfb7a4a82e..0ff37ba185c 100644
--- a/lib/api/v3/utilities/endpoints/index.rb
+++ b/lib/api/v3/utilities/endpoints/index.rb
@@ -135,7 +135,11 @@ module API
end
def render_error(query)
- raise ::API::Errors::InvalidQuery.new(query.errors.full_messages)
+ api_errors = query.errors.full_messages.map do |message|
+ ::API::Errors::InvalidQuery.new(message)
+ end
+
+ raise ::API::Errors::MultipleErrors.create_if_many api_errors
end
def calculated_self_path(request)
diff --git a/lib/api/v3/utilities/params_to_query.rb b/lib/api/v3/utilities/params_to_query.rb
index 6b67a4bbc30..caa1c3b1c89 100644
--- a/lib/api/v3/utilities/params_to_query.rb
+++ b/lib/api/v3/utilities/params_to_query.rb
@@ -46,7 +46,11 @@ module API
representer,
self_link)
else
- raise ::API::Errors::InvalidQuery.new(query.errors.full_messages)
+ api_errors = query.errors.full_messages.map do |message|
+ ::API::Errors::InvalidQuery.new(message)
+ end
+
+ raise ::API::Errors::MultipleErrors.create_if_many api_errors
end
end
diff --git a/modules/documents/lib/api/v3/documents/documents_api.rb b/modules/documents/lib/api/v3/documents/documents_api.rb
index 23e0de795c2..ac724272205 100644
--- a/modules/documents/lib/api/v3/documents/documents_api.rb
+++ b/modules/documents/lib/api/v3/documents/documents_api.rb
@@ -45,7 +45,11 @@ module API
per_page: resolve_page_size(params[:pageSize]),
current_user:)
else
- raise ::API::Errors::InvalidQuery.new(query.errors.full_messages)
+ api_errors = query.errors.full_messages.map do |message|
+ ::API::Errors::InvalidQuery.new(message)
+ end
+
+ raise ::API::Errors::MultipleErrors.create_if_many api_errors
end
end
diff --git a/modules/grids/app/controllers/api/v3/grids/grids_api.rb b/modules/grids/app/controllers/api/v3/grids/grids_api.rb
index f0508a67d38..a0bb01d2e45 100644
--- a/modules/grids/app/controllers/api/v3/grids/grids_api.rb
+++ b/modules/grids/app/controllers/api/v3/grids/grids_api.rb
@@ -48,7 +48,11 @@ module API
per_page: resolve_page_size(params[:pageSize]),
current_user:)
else
- raise ::API::Errors::InvalidQuery.new(query.errors.full_messages)
+ api_errors = query.errors.full_messages.map do |message|
+ ::API::Errors::InvalidQuery.new(message)
+ end
+
+ raise ::API::Errors::MultipleErrors.create_if_many api_errors
end
end
diff --git a/spec/requests/api/v3/capability_resource_spec.rb b/spec/requests/api/v3/capability_resource_spec.rb
index 1fb9c1b1f64..c74494807cf 100644
--- a/spec/requests/api/v3/capability_resource_spec.rb
+++ b/spec/requests/api/v3/capability_resource_spec.rb
@@ -259,9 +259,9 @@ describe 'API v3 capabilities resource', type: :request, content_type: :json do
} }]
end
- it 'returns 400' do
+ it 'returns 422' do
expect(subject.status)
- .to be 400
+ .to be 422
end
it 'communicates the error message' do
@@ -270,7 +270,7 @@ describe 'API v3 capabilities resource', type: :request, content_type: :json do
.at_path('_type')
expect(subject.body)
- .to be_json_eql('urn:openproject-org:api:v3:errors:InvalidQuery'.to_json)
+ .to be_json_eql('urn:openproject-org:api:v3:errors:MultipleErrors'.to_json)
.at_path('errorIdentifier')
end
end