-
Notifications
You must be signed in to change notification settings - Fork 985
Closed
Labels
Description
[REQUIRED] Describe your environment
- Operating System version: Ubuntu 20.10
- Browser version: Chrome 96.0.4664.45 64b
- Firebase SDK version: 9.5.0
- Firebase Product: firestore, auth, storage
[REQUIRED] Describe the problem
To handle Firebase errors in a generic way I had to do dangerous type assertions to calm TypeScript down.
Firestore is a part of Firebase but, according to TypeScript, FirestoreError is not a FirebaseError.
But AuthError is a FirebaseError, just like StorageError (looks like at least).
But StorageError has a special attribute serverResponse, not nested into customData like AuthError does…
Wat?
Here are the incriminated TypeScript interfaces:
/** An error returned by a Firestore operation. */
export declare class FirestoreError extends Error {
/**
* The backend error code associated with this error.
*/
readonly code: FirestoreErrorCode;
/**
* A custom error description.
*/
readonly message: string;
/** The custom name for all FirestoreErrors. */
readonly name: string;
/** The stack of the error. */
readonly stack?: string;
private constructor();
}/**
* Interface for an `Auth` error.
*
* @public
*/
export declare interface AuthError extends FirebaseError {
/** Details about the Firebase Auth error. */
readonly customData: {
/** The name of the Firebase App which triggered this error. */
readonly appName: string;
/** The email address of the user's account, used for sign-in and linking. */
readonly email?: string;
/** The phone number of the user's account, used for sign-in and linking. */
readonly phoneNumber?: string;
/**
* The tenant ID being used for sign-in and linking.
*
* @remarks
* If you use {@link signInWithRedirect} to sign in,
* you have to set the tenant ID on the {@link Auth} instance again as the tenant ID is not persisted
* after redirection.
*/
readonly tenantId?: string;
};
}/**
* An error returned by the Firebase Storage SDK.
* @public
*/
export declare interface StorageError {
/**
* A server response message for the error, if applicable.
*/
serverResponse: string | null;
code: string;
customData?: Record<string, unknown>;
name: 'FirebaseError';
message: string;
stack?: string;
}export declare class FirebaseError extends Error {
readonly code: string;
customData?: Record<string, unknown> | undefined;
readonly name = "FirebaseError";
constructor(code: string, message: string, customData?: Record<string, unknown> | undefined);
}So two little requests 🙏
- Could it be possible for
FirestoreErrorto actually be aFirebaseErrorjust like other Firebase errors? - Would it be possible for all
FirebaseError, includingStorageError, to simply havecode,name,messageandstackattributes, and all other error details nested intocustomData(as it was done forAuthError)?
That would make my day.
Cheers,
Laurent