小编shm*_*les的帖子

Firebase 函数如何正确处理错误

注意:这个问题主要是关于错误处理,如果这是一个好的方法,而不是关于嵌套承诺,请在关闭前阅读

由于目前没有诸如 firestore 和 firebase 数据库之类的服务的错误代码,我正在使用一个系统来了解函数在哪里失败并相应地处理错误,简化版本如下:

exports.doStuff = functions.https.onCall((data, context) => {

    return [promise doing stuff goes here].catch(error => { throw new Error('ERROR0') })
        .then(result => {
            return [promise doing stuff goes here, needs result of previous promise]
                .catch(error => { throw new Error('ERROR1') })
        })
        .then(result => {
            return [promise doing stuff goes here, needs result of previous promise]
                .catch(error => { throw new Error('ERROR2') })
        })
        .then(result => {
            //inform client function successful
            return {
                success: true
            } …
Run Code Online (Sandbox Code Playgroud)

javascript error-handling firebase google-cloud-functions

4
推荐指数
1
解决办法
3739
查看次数

firestore security rules get value of dynamic key?

document structure:

{
    [id 1] {
        field1: "value",
        field2: "value",
        field3: "value"
    }
    [id 2] {
        field1: "value",
        field2: "value",
        field3: "value"
    }
    [id 3] {
        field1: "value",
        field2: "value",
        field3: "value"
    }
}
Run Code Online (Sandbox Code Playgroud)

the map ids reference documents and cannot be hardcoded, but field names (field1, field2...), are the same in each map

is there a way to check that only 1 field in any 1 map is changed, and allow write if those conditions are met?

firebase-security google-cloud-firestore

3
推荐指数
1
解决办法
384
查看次数