Skip to content

Commit

Permalink
display more detailed error information.
Browse files Browse the repository at this point in the history
  • Loading branch information
choykarl committed Dec 30, 2023
1 parent 50c01b9 commit da70ef8
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions Easydict/Feature/Service/Ali/AliService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,16 @@ class AliService: QueryService {
completion(result, EZError(type: .API, description: value.Code?.stringValue, errorDataMessage: value.Message))
}
case let .failure(error):
print("ali api translate error: \(error.errorDescription ?? "")")

let ezError = EZError(nsError: error, errorDataMessage: error.errorDescription)
var msg: String?
if let data = response.data {
let res = try? JSONDecoder().decode(AliAPIResponse.self, from: data)
msg = res?.Message
} else {
msg = error.errorDescription
}

completion(result, ezError)
print("ali api translate error: \(msg ?? "")")
completion(result, EZError(nsError: error, errorDataMessage: msg))
}
}

Expand Down Expand Up @@ -263,9 +268,16 @@ class AliService: QueryService {
}

} else {
print("ali web translate error: \(error.errorDescription ?? "")")
let ezError = EZError(nsError: error, errorDataMessage: error.errorDescription)
completion(result, ezError)
var msg: String?
if let data = response.data {
let res = try? JSONDecoder().decode(AliWebResponse.self, from: data)
msg = res?.message
} else {
msg = error.errorDescription
}

print("ali web translate error: \(msg ?? "")")
completion(result, EZError(nsError: error, errorDataMessage: msg))
}
}
}
Expand Down

0 comments on commit da70ef8

Please sign in to comment.