gpt4 book ai didi

firebase - 检测 Firestore 错误

转载 作者:行者123 更新时间:2023-12-04 17:25:39 25 4
gpt4 key购买 nike

所以我想要一种方法能够在我的 javascript 代码中检测到这个错误

@firebase/firestore:Firestore (7.19.1):FirebaseError:[code=resource-exhausted]:超出配额。

我在控制台中看到了它,但是 catch 无法获取它,也无法在 try 或 then 中获取:/

try {
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "****VHhbGqI",
authDomain: "****m-sum-235202.firebaseapp.com",
databaseURL: "https://**'' '' m-sum-235202.firebaseio.com",
projectId: "premium-sum-235202",
storageBucket: "***'' '' 02.appspot.com",
messagingSenderId: "428499848193",
appId: "1:*******8193:web:520bc61504450a2e458400"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
console.log('daq')

console.log('daq2')
firebase.firestore().collection('testf').doc('test1').set({"zack9": firebase.firestore.FieldValue.increment(1)} , {merge: true }).then((data) => { alert(data) }).catch((error) => { alert('te') })
console.log('daq9')
} catch(error) {
console.log('daqaa')
console.log(error)
}

// tried this too

async function zack () {
try {
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "×**'' *****BHuNxsY5VHhbGqI",
authDomain: "*'' '' '202.firebaseapp.com",
databaseURL: "https://***' '' eio.com",
projectId: "*****sum-235202",
storageBucket: "**'*' '202.appspot.com",
messagingSenderId: "**' *848193",
appId: "1:428499848193:web:****20bc61504450a2e458400"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
console.log('daq')

console.log('daq2')
await firebase.firestore().collection('test').doc('test1').set({"zack9": firebase.firestore.FieldValue.increment(1)} , {merge: true })
console.log('daq9')
} catch(error) {
console.log('daqaa')
console.log(error)
}
}
zack()

最佳答案

不幸的是,无法通过代码跟踪与配额相关的错误。如官方文档中所述,与定价相关 - 可访问 here - 如您所述,此信息只能通过控制台获得,您可以在其中跟踪已使用了多少配额。

考虑到您遇到了超出配额的错误,我建议您尝试限制您将对数据库执行的读取和写入量 - 实际上,您需要限制定价中的任何点这可能会导致您出现此错误 - 因此您可以避免此类错误。有很多方法可以实现,比如使用 limit() 方法来限制你的调用,你可以执行更具体的查询以返回更少的结果,返回的信息更准确等。我会推荐你看看这个教程here ,关于这方面的好例子。

除此之外,您始终可以在 Google's Issue Tracker 上创建功能请求,以供将来实现。

关于firebase - 检测 Firestore 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63629031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com