Skip to content

Commit

Permalink
移除警告
Browse files Browse the repository at this point in the history
  • Loading branch information
Finb committed Sep 24, 2024
1 parent adf0c17 commit 0bbfcb8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Common/Error+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

extension String: Error {}
extension String: @retroactive Error {}

public enum ApiError: Swift.Error {
case Error(info: String)
Expand Down
28 changes: 11 additions & 17 deletions Common/Moya/Observable+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ import UIKit
extension Observable where Element: Moya.Response {
/// 过滤 HTTP 错误,例如超时,请求失败等
func filterHttpError() -> Observable<Result<Element, ApiError>> {
return
catchErrorJustReturn(Element(statusCode: 599, data: Data()))
.map { response -> Result<Element, ApiError> 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<Element, ApiError> in
if (200...209) ~= response.statusCode {
return .success(response)
} else {
return .failure(ApiError.Error(info: "网络错误"))
}
}
}

/// 过滤逻辑错误,例如协议里返回 错误CODE
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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 转换失败"))
}
}
Expand Down
3 changes: 1 addition & 2 deletions View/iCloudStatusCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0bbfcb8

Please sign in to comment.