Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set FirebaseError name to be calling constructors name #8553

Open
wants to merge 3 commits into
base: v11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-walls-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/util': patch
---

Set FirebaseError names to be the calling constructors name.
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
8 changes: 3 additions & 5 deletions packages/util/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export type ErrorMap<ErrorCode extends string> = {
readonly [K in ErrorCode]: string;
};

const ERROR_NAME = 'FirebaseError';

export interface StringLike {
toString(): string;
}
Expand All @@ -72,9 +70,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 +79,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
Loading