diff --git a/Easydict/Feature/Service/Tencent/TencentResponse.swift b/Easydict/Feature/Service/Tencent/TencentResponse.swift index 71c2ff8ba..61b1e7329 100644 --- a/Easydict/Feature/Service/Tencent/TencentResponse.swift +++ b/Easydict/Feature/Service/Tencent/TencentResponse.swift @@ -32,14 +32,29 @@ struct TencentResponse: Codable { */ struct TencentErrorResponse: Codable { struct Response: Codable { - var Error: Error - var RequestId: String + var error: Error + var requestId: String + + // CodingKeys 枚举用于映射字段名 + private enum CodingKeys: String, CodingKey { + case error = "Error" // error --> Error + case requestId = "RequestId" // requestId --> RequestId + } } struct Error: Codable { - var Code: String - var Message: String + var code: String + var message: String + + private enum CodingKeys: String, CodingKey { + case code = "Code" // code --> Code + case message = "Message" // message --> Message + } } - var Response: Response + var response: Response + + private enum CodingKeys: String, CodingKey { + case response = "Response" // response --> Response + } } diff --git a/Easydict/Feature/Service/Tencent/TencentService.swift b/Easydict/Feature/Service/Tencent/TencentService.swift index 3923dd331..f9ff8632b 100644 --- a/Easydict/Feature/Service/Tencent/TencentService.swift +++ b/Easydict/Feature/Service/Tencent/TencentService.swift @@ -116,7 +116,7 @@ public final class TencentService: QueryService { if let data = response.data { do { let errorResponse = try JSONDecoder().decode(TencentErrorResponse.self, from: data) - result.errorMessage = errorResponse.Response.Error.Message + result.errorMessage = errorResponse.response.error.message } catch { NSLog("Failed to decode error response: \(error)") }