From 0bbfcb8781ce0e323f48b4b723fe6abba3234865 Mon Sep 17 00:00:00 2001 From: Fin Date: Tue, 24 Sep 2024 11:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/Error+Extension.swift | 2 +- Common/Moya/Observable+Extension.swift | 28 ++++++++++---------------- View/iCloudStatusCell.swift | 3 +-- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/Common/Error+Extension.swift b/Common/Error+Extension.swift index 6d888ca5..c96c36d2 100644 --- a/Common/Error+Extension.swift +++ b/Common/Error+Extension.swift @@ -8,7 +8,7 @@ import Foundation -extension String: Error {} +extension String: @retroactive Error {} public enum ApiError: Swift.Error { case Error(info: String) diff --git a/Common/Moya/Observable+Extension.swift b/Common/Moya/Observable+Extension.swift index 089906e6..6bb95da8 100644 --- a/Common/Moya/Observable+Extension.swift +++ b/Common/Moya/Observable+Extension.swift @@ -17,16 +17,14 @@ import UIKit extension Observable where Element: Moya.Response { /// 过滤 HTTP 错误,例如超时,请求失败等 func filterHttpError() -> Observable> { - return - catchErrorJustReturn(Element(statusCode: 599, data: Data())) - .map { response -> Result in - if (200 ... 209) ~= response.statusCode { - return .success(response) - } - else { - return .failure(ApiError.Error(info: "网络错误")) - } + return catchAndReturn(Element(statusCode: 599, data: Data())) + .map { response -> Result in + if (200...209) ~= response.statusCode { + return .success(response) + } else { + return .failure(ApiError.Error(info: "网络错误")) } + } } /// 过滤逻辑错误,例如协议里返回 错误CODE @@ -43,16 +41,14 @@ extension Observable where Element: Moya.Response { code == 200 { return .success(json) - } - else { + } else { var msg: String = "" if json["message"].exists() { msg = json["message"].rawString()! } return .failure(ApiError.Error(info: msg)) } - } - catch { + } catch { return .failure(ApiError.Error(info: error.rawString())) } case .failure(let error): @@ -76,8 +72,7 @@ extension Observable where Element: Moya.Response { } if let model: T = self.resultFromJSON(json: rootJson) { return .success(model) - } - else { + } else { return .failure(ApiError.Error(info: "json 转换失败")) } case .failure(let error): @@ -103,8 +98,7 @@ extension Observable where Element: Moya.Response { for json in jsonArray { if let jsonModel: T = self.resultFromJSON(json: json) { result.append(jsonModel) - } - else { + } else { return .failure(ApiError.Error(info: "json 转换失败")) } } diff --git a/View/iCloudStatusCell.swift b/View/iCloudStatusCell.swift index bdb68eb6..51cf1b6a 100644 --- a/View/iCloudStatusCell.swift +++ b/View/iCloudStatusCell.swift @@ -22,8 +22,7 @@ class iCloudStatusCell: UITableViewCell { switch status { case .available: self.detailTextLabel?.text = NSLocalizedString("available") - - case .noAccount, .restricted: + case .noAccount, .restricted, .temporarilyUnavailable: self.detailTextLabel?.text = NSLocalizedString("restricted") case .couldNotDetermine: self.detailTextLabel?.text = NSLocalizedString("unknown")