Skip to content

Commit

Permalink
perf: map error response --> Response
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng authored and Jerry23011 committed Dec 3, 2023
1 parent 2848e10 commit 2e49e6f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions Easydict/Feature/Service/Tencent/TencentResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion Easydict/Feature/Service/Tencent/TencentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
Expand Down

0 comments on commit 2e49e6f

Please sign in to comment.