Android 如何显示可调用云函数的错误?
从中的文档中 我可以使用如下语法抛出错误Android 如何显示可调用云函数的错误?,android,firebase,google-cloud-functions,Android,Firebase,Google Cloud Functions,从中的文档中 我可以使用如下语法抛出错误 throw new functions.https.HttpsError('failed-precondition', 'The function must be called ' + 'while authenticated.'); 在安卓设备中 private fun addMessage(text: String): Task<String> { // Create the arguments to the cal
throw new functions.https.HttpsError('failed-precondition', 'The function must be called ' +
'while authenticated.');
在安卓设备中
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
}
// ...
}
// ...
})
private fun addMessage(文本:字符串):任务{
//创建可调用函数的参数。
val data=hashMapOf(
“文本”到文本,
“推”成真
)
返回函数
.GetHttpScalable(“添加消息”)
.呼叫(数据)
.continueWith{task->
//此延续在成功或失败时运行,但如果任务
//已失败,则结果将引发异常,该异常将
//向下传播。
val result=task.result?.data作为字符串
结果
}
}
添加消息(输入消息)
.addOnCompleteListener(OnCompleteListener{task->
如果(!task.isSuccessful){
val e=task.exception
如果(e是FirebaseFunctionsException){
val代码=e.code
val details=e.details
}
// ...
}
// ...
})
如何获取从云函数抛出的错误消息?我想使用toast显示来自云函数的错误消息
验证时必须调用函数“+”
Android的语法很奇怪。细节?但是细节是any
消息“验证时必须调用函数。”
将设置为本机异常的消息
因此,要使用它,您将获得e.message
的值
关于e.details
,这是一个可选对象,包含作为functions.https.HttpsError
的第三个参数传递的数据
因此,对于以下异常,e.details
将包含缺少的参数名称:
throw new functions.https.HttpsError('failed-precondition', 'Missing required parameter', 'count');