从 iOS 应用程序调用云函数如下所示:
var functions = Functions.functions()
functions.httpsCallable(name).call(data){ (result, error) in
// Code here
}
如何从我的云函数发送错误,以便在上面的代码中拾取该错误?例如:
云功能:
exports.joinGame = functions.https.onCall((data, context) => {
return Error("The game is full")
})
SwiftUI:
var functions = Functions.functions()
functions.httpsCallable("joinGame").call(data){ (result, error) in
print(error) // "The game is full"
}
最佳答案
我仍然不确定你想在哪里返回错误...但这里有一些可能的处理变体:
@State private var error: Error?
var body: some View {
VStack {
Text("Wait for Error")
.onAppear {
functions.httpsCallable("joinGame").call(data){ (result, error) in
print(error) // "The game is full"
DispatchQueue.main.async {
self.error = error
}
}
}
if nil != error {
Text("Got error!") // << do anything with error here
}
}
.onChange(of: error) { newError in
// << or here
}
}
关于ios - 如何从HTTPS云函数返回错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64983057/