1

Is it possible to access Firestore error codes enum with the JS SDK?

I mean, something like firebase.firestore.FirestoreErrorCode

I need to access them in order to translate my app errors

2 Answers 2

2

You can see the errors defined here - https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/util/error.ts

It looks like FirestoreErrorCode and FirestoreError are exported from the index of the package.

FirestoreErrorCode is an union type of the possible error codes while FireStoreError is a throwable Error object.

Because FirestoerErrorCode is defined as a union of literal strings you can't use those strings directly in your code. If they were defined an enum you would be able to access values through the enum properties.

1
  • is it the only way to access all the firebase services error codes to write them separately in my code? I can't find any way to import them
    – Raul
    Nov 25, 2021 at 4:01
1

For Firebase Authentication, you can access them like this:

import { AuthErrorCodes } from 'firebase/auth';

Then you can use it like so:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.