【发布时间】:2020-02-10 05:09:12
【问题描述】:
来自here中的文档
我可以使用这样的语法抛出错误
throw new functions.https.HttpsError('failed-precondition', 'The function must be called ' +
'while authenticated.');
在 Android 设备中
private fun addMessage(text: String): Task<String> {
// Create the arguments to the callable function.
val data = hashMapOf(
"text" to text,
"push" to true
)
return functions
.getHttpsCallable("addMessage")
.call(data)
.continueWith { task ->
// This continuation runs on either success or failure, but if the task
// has failed then result will throw an Exception which will be
// propagated down.
val result = task.result?.data as String
result
}
}
addMessage(inputMessage)
.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
val e = task.exception
if (e is FirebaseFunctionsException) {
val code = e.code
val details = e.details
}
// ...
}
// ...
})
如何获得从云函数抛出的错误消息?我想使用 toast 显示来自云功能的错误消息
该函数必须在认证时调用'+'。
Android 中的语法很奇怪。在细节?但细节是any
【问题讨论】:
标签: android firebase google-cloud-functions