[ad_1]
I’m writing a closure with error dealing with, however I get a warning “‘catch’ block is unreachable as a result of no errors are thrown in ‘do’ block” within the catch line.
That is my code:
class Service {
func graphQL(physique: [String:Any], onSuccess: @escaping (Basis.Information) -> (), onFailure: @escaping (Error) -> ()) {
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("utility/json", forHTTPHeaderField: "Content material-Sort")
request.httpBody = strive? JSONSerialization.knowledge(withJSONObject: physique, choices: .fragmentsAllowed)
URLSession.shared.dataTask(with: request) { (knowledge, response, error) in
if let error = error {
onFailure(error)
}
if let knowledge = knowledge {
do{
onSuccess(knowledge)
}
catch{
onFailure(error)
}
}
}.resume()
}
class TimeDepositManager {
func getTimeDeposits(onSuccess: @escaping ([TimeDeposits]) -> (), onFailure: @escaping (Error) -> ()) {
let physique = ["query": "{ account { timeDeposits { returnAmount interestRate dueDate originalAmount id startDate currency } } }"
]
Service().graphQL(physique: physique, onSuccess: { knowledge in
let json = strive? JSONDecoder().decode(GraphQLResponse.self, from: knowledge)
onSuccess(json?.knowledge?.account?.timeDeposits ?? [])
}, onFailure: { error in
print(error)
})
}
I would like the logic of onSuccess within the func getTimeDeposits(), however how take away this catch block warning?
[ad_2]
