mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
Harden handling of Nextcloud errors
A status of 500+ in ocs.meta indicates that something went so wrong, that we shouldn't rely on the ocs.data being filled with what we usually expect to be there.
This commit is contained in:
@@ -78,6 +78,17 @@ module Storages
|
||||
Failure(error.with(payload: "No origin user ID or user token found. Cannot execute query without user context."))
|
||||
end
|
||||
end
|
||||
|
||||
# Validates the OCS Meta Statuscode for fatal errors (i.e. unexpected server-side errors). Client-side errors,
|
||||
# such as a 404 File Not Found do not cause an error.
|
||||
# @return [Dry::Result]
|
||||
def fail_on_ocs_error(json, error)
|
||||
if json.dig(:ocs, :meta, :statuscode) < 500
|
||||
Success(json)
|
||||
else
|
||||
Failure(error.with(code: :error))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ module Storages
|
||||
|
||||
case response
|
||||
in { status: 200..299 }
|
||||
Success(response.json(symbolize_keys: true))
|
||||
fail_on_ocs_error(response.json(symbolize_keys: true), error)
|
||||
in { status: 404 }
|
||||
Failure(error.with(code: :not_found))
|
||||
in { status: 401 }
|
||||
|
||||
+1
-9
@@ -57,7 +57,7 @@ module Storages
|
||||
|
||||
case response
|
||||
in { status: 200..299 }
|
||||
verify_successful_response(response.json(symbolize_keys: true), error)
|
||||
fail_on_ocs_error(response.json(symbolize_keys: true), error)
|
||||
in { status: 404 }
|
||||
Failure(error.with(code: :not_found))
|
||||
in { status: 401 }
|
||||
@@ -67,14 +67,6 @@ module Storages
|
||||
end
|
||||
end
|
||||
|
||||
def verify_successful_response(json, error)
|
||||
if json.dig(:ocs, :meta, :status) == "ok"
|
||||
Success(json)
|
||||
else
|
||||
Failure(error.with(code: :error))
|
||||
end
|
||||
end
|
||||
|
||||
def create_storage_file_infos(parsed_json)
|
||||
parsed_json.dig(:ocs, :data)&.map do |(key, value)|
|
||||
if value[:statuscode] == 200
|
||||
|
||||
@@ -141,6 +141,7 @@ module StorageServerHelpers
|
||||
folder1_xml_response = build(:webdav_data_folder)
|
||||
folder1_fileinfo_response = {
|
||||
ocs: {
|
||||
meta: { statuscode: 100 },
|
||||
data: {
|
||||
status: "OK",
|
||||
statuscode: 200,
|
||||
|
||||
Reference in New Issue
Block a user