From b6f6c0cf973ef18f560c1803f22d9442e4d4d33c Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 21 Oct 2024 16:41:39 +0200 Subject: [PATCH] RESPONSE ERROR - CENTRALIZED Signed-off-by: Marino Faggiana --- iOSClient/NCGlobal.swift | 1 + iOSClient/Networking/NCNetworking.swift | 15 ++++++++++++++- iOSClient/Networking/NCService.swift | 2 -- .../Supporting Files/en.lproj/Localizable.strings | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 0417b66202..295ffb83ec 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -201,6 +201,7 @@ class NCGlobal: NSObject { let errorPreconditionFailed: Int = 412 let errorUnsupportedMediaType: Int = 415 let errorInternalServerError: Int = 500 + let errorMaintenance: Int = 503 let errorQuota: Int = 507 let errorUnauthorized997: Int = 997 let errorExplicitlyCancelled: Int = -999 diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift index 849fd99180..abe1353419 100644 --- a/iOSClient/Networking/NCNetworking.swift +++ b/iOSClient/Networking/NCNetworking.swift @@ -164,7 +164,20 @@ class NCNetworking: NSObject, NextcloudKitDelegate { #endif } - func request(_ request: Alamofire.DataRequest, didParseResponse response: Alamofire.AFDataResponse) { } + func request(_ request: Alamofire.DataRequest, didParseResponse response: Alamofire.AFDataResponse) { + /// RESPONSE ERROR + if let statusCode = response.response?.statusCode { + switch statusCode { + case NCGlobal.shared.errorMaintenance: + if let errorDescription = NKError.getErrorDescription(for: statusCode) { + let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: errorDescription) + NCContentPresenter().showWarning(error: error, priority: .max) + } + default: + break + } + } + } // MARK: - diff --git a/iOSClient/Networking/NCService.swift b/iOSClient/Networking/NCService.swift index 79fa0ea051..286c37ae34 100644 --- a/iOSClient/Networking/NCService.swift +++ b/iOSClient/Networking/NCService.swift @@ -95,8 +95,6 @@ class NCService: NSObject { switch await NCNetworking.shared.getServerStatus(serverUrl: serverUrl, options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { case .success(let serverInfo): if serverInfo.maintenance { - let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_maintenance_mode_") - NCContentPresenter().showWarning(error: error, priority: .max) return false } else if serverInfo.productName.lowercased().contains("owncloud") { let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_warning_owncloud_") diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index be8ac8a914..58d42e1c27 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -1030,7 +1030,7 @@ "_user_" = "User"; "_add_subtitle_" = "Add an external subtitle"; "_add_audio_" = "Add an external audio"; -"_maintenance_mode_" = "Server is currently in maintenance mode"; +"_server_maintenance_mode_" = "Server is currently in maintenance mode"; "_upload_foreground_msg_" = "Do not close %@ to complete the transfer …"; "_upload_background_msg_" = "Files upload in progress …"; "_create_folder_error_" = "An error has occurred while creating the folder:\n%@.\n\nPlease resolve the issue as soon as possible.\n\nAll uploads are suspended until the problem is resolved.\n";