Firestore JS SDK-如何访问FirestoreErrorCode枚举



是否可以使用JS SDK访问Firestore错误代码枚举?

我的意思是,类似firebase.firestore.FirestoreErrorCode的东西

我需要访问它们来翻译我的应用程序错误

您可以看到这里定义的错误-https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/util/error.ts

看起来FirestoreErrorCodeFirestoreError是从包的索引中导出的。

FirestoreErrorCode是可能的错误代码的并集类型,而FireStoreError是可丢弃的错误对象。

因为FirestoerErrorCode被定义为文本字符串的并集,所以不能在代码中直接使用这些字符串。如果它们被定义为枚举,您将能够通过枚举属性访问值。

对于Firebase身份验证,您可以这样访问它们:

import { AuthErrorCodes } from 'firebase/auth';

然后你可以这样使用它:

if (error.code === AuthErrorCodes.USER_DELETED) {
...
}

最新更新