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

Better error handling

Marcello Rocha6b42b54beea4
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb
index 919e8295a5a..cf06a4fcb1f 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb
@@ -51,13 +51,30 @@ module Storages
if Net::HTTPRedirection === response
ServiceResult.success(result: response.header['Location'])
else
- ServiceResult.failure(result: :error, errors: ::Storages::StorageError.new(code: :error, data: response.body))
+ handle_errors(response)
end
end
end
private
+ def handle_errors(response)
+ case response
+ when Net::HTTPNotFound
+ ServiceResult.failure(result: :not_found,
+ errors: ::Storages::StorageError.new(code: :not_found, data: response.body))
+ when Net::HTTPForbidden
+ ServiceResult.failure(result: :forbidden,
+ errors: ::Storages::StorageError.new(code: :forbidden, data: response.body))
+ when Net::HTTPUnauthorized
+ ServiceResult.failure(result: :unauthorized,
+ errors: ::Storages::StorageError.new(code: :unauthorized, data: response.body))
+ else
+ ServiceResult.failure(result: :error,
+ errors: ::Storages::StorageError.new(code: :error, data: response.body))
+ end
+ end
+
def uri_path_for(file_id)
"/v1.0/drives/#{@storage.drive_id}/items/#{file_id}"
end