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

[#47207] extract error handling

Eric Schuberta2cc8123a674
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb
index 51b2d10a416..896a0ecdf0f 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb
@@ -29,6 +29,7 @@
module Storages::Peripherals::StorageInteraction::Nextcloud
class DownloadLinkQuery < Storages::Peripherals::StorageInteraction::StorageQuery
include API::V3::Utilities::PathHelper
+ include Errors
using Storages::Peripherals::ServiceResultRefinements
def initialize(base_uri:, token:, retry_proc:)
@@ -86,13 +87,6 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
# rubocop:enable Metrics/AbcSize
- def error(code, log_message = nil, data = nil)
- ServiceResult.failure(
- result: code, # This is needed to work with the ConnectionManager token refresh mechanism.
- errors: Storages::StorageError.new(code:, log_message:, data:)
- )
- end
-
def download_link(token, origin_name)
api_v3_paths.join_uri_path(@base_uri, 'index.php/apps/integration_openproject/direct', token, CGI.escape(origin_name))
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/errors.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/errors.rb
new file mode 100644
index 00000000000..8ed761faae3
--- /dev/null
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/errors.rb
@@ -0,0 +1,38 @@
+#-- 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 Storages::Peripherals::StorageInteraction::Nextcloud
+ module Errors
+ def error(code, log_message = nil, data = nil)
+ ServiceResult.failure(
+ result: code, # This is needed to work with the ConnectionManager token refresh mechanism.
+ errors: Storages::StorageError.new(code:, log_message:, data:)
+ )
+ end
+ end
+end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_query.rb
index 17b75b70fb0..a0f7c44cd31 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_query.rb
@@ -29,6 +29,7 @@
module Storages::Peripherals::StorageInteraction::Nextcloud
class FileQuery < Storages::Peripherals::StorageInteraction::StorageQuery
include API::V3::Utilities::PathHelper
+ include Errors
using Storages::Peripherals::ServiceResultRefinements
FILE_INFO_PATH = 'ocs/v1.php/apps/integration_openproject/fileinfo'.freeze
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb
index 030425ef9d0..f5e8522bb8c 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb
@@ -29,6 +29,7 @@
module Storages::Peripherals::StorageInteraction::Nextcloud
class UploadLinkQuery < Storages::Peripherals::StorageInteraction::StorageQuery
include API::V3::Utilities::PathHelper
+ include Errors
using Storages::Peripherals::ServiceResultRefinements # use '>>' (bind) operator for ServiceResult
URI_TOKEN_REQUEST = 'index.php/apps/integration_openproject/direct-upload-token'.freeze
@@ -115,13 +116,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
# rubocop:enable Style/OpenStructUse Style/MultilineBlockChain
end
end
- # rubocop:enable Metrics/AbcSize
- def error(code, log_message = nil, data = nil)
- ServiceResult.failure(
- result: code, # This is needed to work with the ConnectionManager token refresh mechanism.
- errors: Storages::StorageError.new(code:, log_message:, data:)
- )
- end
+ # rubocop:enable Metrics/AbcSize
end
end