Manos Chorianopoulos

getMerchants failureCallback fix

......@@ -2388,7 +2388,8 @@ public final class WarplySDK {
uuid: String = "",
distance: Int = 0,
parentUuids: [String] = [],
completion: @escaping ([MerchantModel]?) -> Void
completion: @escaping ([MerchantModel]?) -> Void,
failureCallback: @escaping (Int) -> Void
) {
// Handle language default inside the method
let finalLanguage = language ?? self.applicationLocale
......@@ -2435,7 +2436,7 @@ public final class WarplySDK {
dynatraceEvent._parameters = nil
self.postFrameworkEvent("dynatrace", sender: dynatraceEvent)
completion(merchantsArray)
failureCallback(-1)
}
}
} catch {
......@@ -2445,7 +2446,11 @@ public final class WarplySDK {
dynatraceEvent._parameters = nil
self.postFrameworkEvent("dynatrace", sender: dynatraceEvent)
completion(nil)
if let networkError = error as? NetworkError {
failureCallback(networkError.code)
} else {
failureCallback(-1)
}
}
}
}
......@@ -2461,7 +2466,8 @@ public final class WarplySDK {
uuid: String = "",
distance: Int = 0,
parentUuids: [String] = [],
completion: @escaping ([MerchantModel]?) -> Void
completion: @escaping ([MerchantModel]?) -> Void,
failureCallback: @escaping (Int) -> Void = { _ in }
) {
// Call new method with nil language (will use applicationLocale)
getMerchants(
......@@ -2473,7 +2479,8 @@ public final class WarplySDK {
uuid: uuid,
distance: distance,
parentUuids: parentUuids,
completion: completion
completion: completion,
failureCallback: failureCallback
)
}
......@@ -2612,14 +2619,18 @@ public final class WarplySDK {
tags: tags,
uuid: uuid,
distance: distance,
parentUuids: parentUuids
) { merchants in
if let merchants = merchants {
continuation.resume(returning: merchants)
} else {
continuation.resume(throwing: WarplyError.networkError)
parentUuids: parentUuids,
completion: { merchants in
if let merchants = merchants {
continuation.resume(returning: merchants)
} else {
continuation.resume(throwing: WarplyError.networkError)
}
},
failureCallback: { errorCode in
continuation.resume(throwing: WarplyError.unknownError(errorCode))
}
}
)
}
}
......