Skip to content

Commit

Permalink
Set FirebaseError names to be calling constructors name
Browse files Browse the repository at this point in the history
  • Loading branch information
dlarocque committed Sep 30, 2024
1 parent 6b035b7 commit 07b203a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion common/api-review/util.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ export class FirebaseError extends Error {
customData?: Record<string, unknown> | undefined);
readonly code: string;
customData?: Record<string, unknown> | undefined;
readonly name: string;
}

// Warning: (ae-missing-release-tag) "FirebaseSignInProvider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down
6 changes: 3 additions & 3 deletions packages/util/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ export interface ErrorData {
// Based on code from:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types
export class FirebaseError extends Error {
/** The custom name for all FirebaseErrors. */
readonly name: string = ERROR_NAME;

constructor(
/** The error code for this error. */
readonly code: string,
Expand All @@ -84,6 +81,9 @@ export class FirebaseError extends Error {
) {
super(message);

// Set the name of the error to the name of the calling constructor.
this.name = this.constructor.name;

// Fix For ES5
// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
// TODO(dlarocque): Replace this with `new.target`: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
Expand Down

0 comments on commit 07b203a

Please sign in to comment.