Skip to content

Commit

Permalink
Fix FirebaseStorageError message recursion bug (#4807)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 authored Apr 20, 2021
1 parent 633463e commit 364e336
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-cooks-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/storage': patch
---

Fix infinite recursion caused by `FirebaseStorageError` message getter.
18 changes: 7 additions & 11 deletions packages/storage/src/implementation/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { CONFIG_STORAGE_BUCKET_KEY } from './constants';
* @public
*/
export class FirebaseStorageError extends FirebaseError {
private readonly _baseMessage: string;
/**
* Stores custom error data unque to FirebaseStorageError.
*/
Expand All @@ -37,6 +38,7 @@ export class FirebaseStorageError extends FirebaseError {
prependCode(code),
`Firebase Storage: ${message} (${prependCode(code)})`
);
this._baseMessage = this.message;
// Without this, `instanceof FirebaseStorageError`, in tests for example,
// returns false.
Object.setPrototypeOf(this, FirebaseStorageError.prototype);
Expand All @@ -49,17 +51,6 @@ export class FirebaseStorageError extends FirebaseError {
return prependCode(code) === this.code;
}

/**
* Error message including serverResponse if available.
*/
get message(): string {
if (this.customData.serverResponse) {
return `${this.message}\n${this.customData.serverResponse}`;
} else {
return this.message;
}
}

/**
* Optional response message that was added by the server.
*/
Expand All @@ -69,6 +60,11 @@ export class FirebaseStorageError extends FirebaseError {

set serverResponse(serverResponse: string | null) {
this.customData.serverResponse = serverResponse;
if (this.customData.serverResponse) {
this.message = `${this._baseMessage}\n${this.customData.serverResponse}`;
} else {
this.message = this._baseMessage;
}
}
}

Expand Down

0 comments on commit 364e336

Please sign in to comment.