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

[#47063] Differenciate nextcloud and open project error responses in API

Eric Schubert87290de4064b
diff --git a/config/locales/en.yml b/config/locales/en.yml
index eabbccc7c36..0ad5ccb6245 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3214,6 +3214,7 @@ en:
code_409: "Could not update the resource because of conflicting modifications."
code_429: "Too many requests. Please try again later."
code_500: "An internal error has occurred."
+ code_500_outbound_request_failure: "An outbound request to another resource has failed with status code %{status_code}."
not_found:
work_package: "The work package you are looking for cannot be found or has been deleted."
expected:
diff --git a/docs/api/apiv3/paths/storage_files_prepare_upload.yml b/docs/api/apiv3/paths/storage_files_prepare_upload.yml
index d620d2fcba1..c551cd0370b 100644
--- a/docs/api/apiv3/paths/storage_files_prepare_upload.yml
+++ b/docs/api/apiv3/paths/storage_files_prepare_upload.yml
@@ -64,8 +64,17 @@ post:
errorIdentifier: urn:openproject-org:api:v3:errors:NotFound
message: The requested resource could not be found.
description: |-
- Returned in either of those cases:
- - if the storage does not exist or the client does not have sufficient permissions to see it
+ Returned the storage does not exist or the client does not have sufficient permissions to see it.
- **Required permission:** view file links
- - if the document root file identification does not exist on the storage
+ **Required permission:** view file links
+ '500':
+ content:
+ application/hal+json:
+ schema:
+ $ref: '../components/schemas/error_response.yml'
+ example:
+ _type: Error
+ errorIdentifier: urn:openproject-org:api:v3:errors:OutboundRequestFailure
+ message: An outbound request to another resource has failed with status code 404.
+ description: |-
+ Returned if the outbound request to the storage has failed with any reason.
diff --git a/lib/api/errors/outbound_request_failure.rb b/lib/api/errors/outbound_request_failure.rb
new file mode 100644
index 00000000000..563bf9afb08
--- /dev/null
+++ b/lib/api/errors/outbound_request_failure.rb
@@ -0,0 +1,40 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module API
+ module Errors
+ class OutboundRequestFailure < ErrorBase
+ identifier 'OutboundRequestFailure'.freeze
+ code 500
+
+ def initialize(status_code)
+ super I18n.t('api_v3.errors.code_500_outbound_request_failure', status_code:)
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/common/storages/peripherals/storage_error_helper.rb b/modules/storages/app/common/storages/peripherals/storage_error_helper.rb
index 9818f1e707f..0146ff740ad 100644
--- a/modules/storages/app/common/storages/peripherals/storage_error_helper.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_error_helper.rb
@@ -33,7 +33,7 @@ module Storages::Peripherals
case error.code
when :not_found
- raise API::Errors::NotFound.new
+ raise API::Errors::OutboundRequestFailure.new(404)
when :bad_request
raise API::Errors::BadRequest.new(error.log_message)
else
diff --git a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
index 6e6a10ff2b5..e6fa20cfa7a 100644
--- a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
+++ b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
@@ -37,12 +37,7 @@ module API::V3::StorageFiles
get do
(files_query(@storage, current_user) >> execute_files_query(params[:parent]))
.match(
- on_success: ->(files) do
- API::V3::StorageFiles::StorageFilesRepresenter.new(
- files,
- current_user:
- )
- end,
+ on_success: ->(files) { API::V3::StorageFiles::StorageFilesRepresenter.new(files, current_user:) },
on_failure: ->(error) { raise_error(error) }
)
end
diff --git a/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb
index 9a9ff2324d5..4a57076598a 100644
--- a/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb
+++ b/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb
@@ -142,7 +142,13 @@ describe 'API v3 storage files', content_type: :json, webmock: true do
)
end
- it { expect(last_response.status).to be(404) }
+ it 'fails with outbound request failure' do
+ expect(last_response.status).to be(500)
+
+ body = JSON.parse(last_response.body)
+ expect(body['message']).to eq(I18n.t('api_v3.errors.code_500_outbound_request_failure', status_code: 404))
+ expect(body['errorIdentifier']).to eq('urn:openproject-org:api:v3:errors:OutboundRequestFailure')
+ end
end
end
@@ -179,7 +185,13 @@ describe 'API v3 storage files', content_type: :json, webmock: true do
describe 'due to not found' do
let(:error) { :not_found }
- it { expect(last_response.status).to be(404) }
+ it 'fails with outbound request failure' do
+ expect(last_response.status).to be(500)
+
+ body = JSON.parse(last_response.body)
+ expect(body['message']).to eq(I18n.t('api_v3.errors.code_500_outbound_request_failure', status_code: 404))
+ expect(body['errorIdentifier']).to eq('urn:openproject-org:api:v3:errors:OutboundRequestFailure')
+ end
end
end
end
@@ -260,7 +272,13 @@ describe 'API v3 storage files', content_type: :json, webmock: true do
)
end
- it { expect(last_response.status).to be(404) }
+ it 'fails with outbound request failure' do
+ expect(last_response.status).to be(500)
+
+ body = JSON.parse(last_response.body)
+ expect(body['message']).to eq(I18n.t('api_v3.errors.code_500_outbound_request_failure', status_code: 404))
+ expect(body['errorIdentifier']).to eq('urn:openproject-org:api:v3:errors:OutboundRequestFailure')
+ end
end
end
end