firebase / firebase/firebase-admin-node

FirebaseError type definition as class instead of interface

Open
#403 21 comments 49 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.7k
Forks
419
Avg merge
3d 10h
Merged PRs (30d)
16

Description

### Description

Currently is `FirebaseError` defined as interface in typescript definition file. So in case of `async/await` we have to handle errors checking e.g. `code` property existence:
```
try {
const decodedIdToken = await this.auth.verifyIdToken(firebaseIdToken);
// some another calls async methods
} catch(err) {
if (err.code === 'auth/argument-error') {
// handle errors - but err is still any type
}
}
```
This is proper way to handle errors but a little bit cleaner way would be:
```
try {
const decodedIdToken = await this.auth.verifyIdToken(firebaseIdToken);
// some another calls async methods
} catch(err) {
if (err instanceof FirebaseError) {
// handle error codes and proper typing here
}
}
```
It is just a small improvement but in this way we have correct type in if statement and also `FirebaseError.code` would be some string literal type with defined all possible error codes.
```
type FirebaseErrorCode = 'auth/argument-error' | 'auth/id-token-expired' | ... ;

class FirebaseError extends Error {
code: FirebaseErrorCode;
}
```
I think this could be really helpful in error handling.

### Target environment

* Operating System version: all
* Firebase SDK version: latest
* Library version: latest
* Firebase Product: common

Contributor guide

Open the contributing guide

Research direction

Start by locating the TypeScript definition for FirebaseError and the auth.verifyIdToken entry point. Compare the current interface with the requested class and FirebaseErrorCode typing, then verify that async error handling supports instanceof without breaking existing consumers.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
authentication
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.