diff --git a/common/api-review/storage.api.md b/common/api-review/storage.api.md index 27ce6e38fe1..d4d6db5f998 100644 --- a/common/api-review/storage.api.md +++ b/common/api-review/storage.api.md @@ -51,11 +51,6 @@ export interface FirebaseStorage extends _FirebaseService { maxUploadRetryTime: number; } -// @public -export interface FirebaseStorageError extends FirebaseError { - serverResponse: string | null; -} - // @internal export class _FirebaseStorageImpl implements FirebaseStorage { constructor( @@ -129,13 +124,13 @@ export function getMetadata(ref: StorageReference): Promise; // @public export function getStorage(app?: FirebaseApp, bucketUrl?: string): FirebaseStorage; -// Warning: (ae-forgotten-export) The symbol "FirebaseStorageError" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "StorageError" needs to be exported by the entry point index.d.ts // // @internal (undocumented) -export function _invalidArgument(message: string): FirebaseStorageError_2; +export function _invalidArgument(message: string): StorageError_2; // @internal (undocumented) -export function _invalidRootOperation(name: string): FirebaseStorageError_2; +export function _invalidRootOperation(name: string): StorageError_2; // @public export function list(ref: StorageReference, options?: ListOptions): Promise; @@ -211,12 +206,17 @@ export interface SettableMetadata { } | undefined; } +// @public +export interface StorageError extends FirebaseError { + serverResponse: string | null; +} + // @public export interface StorageObserver { // (undocumented) complete?: CompleteFn | null; // (undocumented) - error?: (error: FirebaseStorageError) => void | null; + error?: (error: StorageError) => void | null; // (undocumented) next?: NextFn | null; } @@ -233,14 +233,14 @@ export interface StorageReference { } // @public -export type StringFormat = string; +export type StringFormat = typeof StringFormat[keyof typeof StringFormat]; // @public export const StringFormat: { - RAW: string; - BASE64: string; - BASE64URL: string; - DATA_URL: string; + readonly RAW: "raw"; + readonly BASE64: "base64"; + readonly BASE64URL: "base64url"; + readonly DATA_URL: "data_url"; }; // @public @@ -295,12 +295,12 @@ export function uploadString(ref: StorageReference, value: string, format?: stri // @public export interface UploadTask { cancel(): boolean; - catch(onRejected: (error: FirebaseStorageError) => unknown): Promise; - on(event: TaskEvent, nextOrObserver?: StorageObserver | null | ((snapshot: UploadTaskSnapshot) => unknown), error?: ((a: FirebaseStorageError) => unknown) | null, complete?: Unsubscribe | null): Unsubscribe | Subscribe; + catch(onRejected: (error: StorageError) => unknown): Promise; + on(event: TaskEvent, nextOrObserver?: StorageObserver | null | ((snapshot: UploadTaskSnapshot) => unknown), error?: ((a: StorageError) => unknown) | null, complete?: Unsubscribe | null): Unsubscribe | Subscribe; pause(): boolean; resume(): boolean; snapshot: UploadTaskSnapshot; - then(onFulfilled?: ((snapshot: UploadTaskSnapshot) => unknown) | null, onRejected?: ((error: FirebaseStorageError) => unknown) | null): Promise; + then(onFulfilled?: ((snapshot: UploadTaskSnapshot) => unknown) | null, onRejected?: ((error: StorageError) => unknown) | null): Promise; } // @internal @@ -308,18 +308,18 @@ export class _UploadTask { constructor(ref: _Reference, blob: _FbsBlob, metadata?: Metadata | null); _blob: _FbsBlob; cancel(): boolean; - catch(onRejected: (p1: FirebaseStorageError_2) => T | Promise): Promise; + catch(onRejected: (p1: StorageError_2) => T | Promise): Promise; // Warning: (ae-forgotten-export) The symbol "Metadata" needs to be exported by the entry point index.d.ts _metadata: Metadata | null; // Warning: (ae-forgotten-export) The symbol "Unsubscribe" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "Subscribe" needs to be exported by the entry point index.d.ts - on(type: _TaskEvent, nextOrObserver?: StorageObserver | null | ((snapshot: UploadTaskSnapshot) => unknown), error?: ((a: FirebaseStorageError_2) => unknown) | null, completed?: Unsubscribe_2 | null): Unsubscribe_2 | Subscribe_2; + on(type: _TaskEvent, nextOrObserver?: StorageObserver | null | ((snapshot: UploadTaskSnapshot) => unknown), error?: ((a: StorageError_2) => unknown) | null, completed?: Unsubscribe_2 | null): Unsubscribe_2 | Subscribe_2; pause(): boolean; resume(): boolean; get snapshot(): UploadTaskSnapshot; // Warning: (ae-forgotten-export) The symbol "InternalTaskState" needs to be exported by the entry point index.d.ts _state: InternalTaskState; - then(onFulfilled?: ((value: UploadTaskSnapshot) => U | Promise) | null, onRejected?: ((error: FirebaseStorageError_2) => U | Promise) | null): Promise; + then(onFulfilled?: ((value: UploadTaskSnapshot) => U | Promise) | null, onRejected?: ((error: StorageError_2) => U | Promise) | null): Promise; _transferred: number; } diff --git a/packages/storage/src/implementation/error.ts b/packages/storage/src/implementation/error.ts index a603237b455..dab199db8d6 100644 --- a/packages/storage/src/implementation/error.ts +++ b/packages/storage/src/implementation/error.ts @@ -21,10 +21,10 @@ import { CONFIG_STORAGE_BUCKET_KEY } from './constants'; * An error returned by the Firebase Storage SDK. * @public */ -export class FirebaseStorageError extends FirebaseError { +export class StorageError extends FirebaseError { private readonly _baseMessage: string; /** - * Stores custom error data unque to FirebaseStorageError. + * Stores custom error data unque to StorageError. */ customData: { serverResponse: string | null } = { serverResponse: null }; @@ -39,9 +39,9 @@ export class FirebaseStorageError extends FirebaseError { `Firebase Storage: ${message} (${prependCode(code)})` ); this._baseMessage = this.message; - // Without this, `instanceof FirebaseStorageError`, in tests for example, + // Without this, `instanceof StorageError`, in tests for example, // returns false. - Object.setPrototypeOf(this, FirebaseStorageError.prototype); + Object.setPrototypeOf(this, StorageError.prototype); } /** @@ -72,7 +72,7 @@ export const errors = {}; /** * @public - * Error codes that can be attached to `FirebaseStorageError`s. + * Error codes that can be attached to `StorageError`s. */ export const enum StorageErrorCode { // Shared between all platforms @@ -108,36 +108,36 @@ export function prependCode(code: StorageErrorCode): string { return 'storage/' + code; } -export function unknown(): FirebaseStorageError { +export function unknown(): StorageError { const message = 'An unknown error occurred, please check the error payload for ' + 'server response.'; - return new FirebaseStorageError(StorageErrorCode.UNKNOWN, message); + return new StorageError(StorageErrorCode.UNKNOWN, message); } -export function objectNotFound(path: string): FirebaseStorageError { - return new FirebaseStorageError( +export function objectNotFound(path: string): StorageError { + return new StorageError( StorageErrorCode.OBJECT_NOT_FOUND, "Object '" + path + "' does not exist." ); } -export function bucketNotFound(bucket: string): FirebaseStorageError { - return new FirebaseStorageError( +export function bucketNotFound(bucket: string): StorageError { + return new StorageError( StorageErrorCode.BUCKET_NOT_FOUND, "Bucket '" + bucket + "' does not exist." ); } -export function projectNotFound(project: string): FirebaseStorageError { - return new FirebaseStorageError( +export function projectNotFound(project: string): StorageError { + return new StorageError( StorageErrorCode.PROJECT_NOT_FOUND, "Project '" + project + "' does not exist." ); } -export function quotaExceeded(bucket: string): FirebaseStorageError { - return new FirebaseStorageError( +export function quotaExceeded(bucket: string): StorageError { + return new StorageError( StorageErrorCode.QUOTA_EXCEEDED, "Quota for bucket '" + bucket + @@ -146,29 +146,29 @@ export function quotaExceeded(bucket: string): FirebaseStorageError { ); } -export function unauthenticated(): FirebaseStorageError { +export function unauthenticated(): StorageError { const message = 'User is not authenticated, please authenticate using Firebase ' + 'Authentication and try again.'; - return new FirebaseStorageError(StorageErrorCode.UNAUTHENTICATED, message); + return new StorageError(StorageErrorCode.UNAUTHENTICATED, message); } -export function unauthorizedApp(): FirebaseStorageError { - return new FirebaseStorageError( +export function unauthorizedApp(): StorageError { + return new StorageError( StorageErrorCode.UNAUTHORIZED_APP, 'This app does not have permission to access Firebase Storage on this project.' ); } -export function unauthorized(path: string): FirebaseStorageError { - return new FirebaseStorageError( +export function unauthorized(path: string): StorageError { + return new StorageError( StorageErrorCode.UNAUTHORIZED, "User does not have permission to access '" + path + "'." ); } -export function retryLimitExceeded(): FirebaseStorageError { - return new FirebaseStorageError( +export function retryLimitExceeded(): StorageError { + return new StorageError( StorageErrorCode.RETRY_LIMIT_EXCEEDED, 'Max retry time for operation exceeded, please try again.' ); @@ -178,8 +178,8 @@ export function invalidChecksum( path: string, checksum: string, calculated: string -): FirebaseStorageError { - return new FirebaseStorageError( +): StorageError { + return new StorageError( StorageErrorCode.INVALID_CHECKSUM, "Uploaded/downloaded object '" + path + @@ -191,36 +191,36 @@ export function invalidChecksum( ); } -export function canceled(): FirebaseStorageError { - return new FirebaseStorageError( +export function canceled(): StorageError { + return new StorageError( StorageErrorCode.CANCELED, 'User canceled the upload/download.' ); } -export function invalidEventName(name: string): FirebaseStorageError { - return new FirebaseStorageError( +export function invalidEventName(name: string): StorageError { + return new StorageError( StorageErrorCode.INVALID_EVENT_NAME, "Invalid event name '" + name + "'." ); } -export function invalidUrl(url: string): FirebaseStorageError { - return new FirebaseStorageError( +export function invalidUrl(url: string): StorageError { + return new StorageError( StorageErrorCode.INVALID_URL, "Invalid URL '" + url + "'." ); } -export function invalidDefaultBucket(bucket: string): FirebaseStorageError { - return new FirebaseStorageError( +export function invalidDefaultBucket(bucket: string): StorageError { + return new StorageError( StorageErrorCode.INVALID_DEFAULT_BUCKET, "Invalid default bucket '" + bucket + "'." ); } -export function noDefaultBucket(): FirebaseStorageError { - return new FirebaseStorageError( +export function noDefaultBucket(): StorageError { + return new StorageError( StorageErrorCode.NO_DEFAULT_BUCKET, 'No default bucket ' + "found. Did you set the '" + @@ -229,22 +229,22 @@ export function noDefaultBucket(): FirebaseStorageError { ); } -export function cannotSliceBlob(): FirebaseStorageError { - return new FirebaseStorageError( +export function cannotSliceBlob(): StorageError { + return new StorageError( StorageErrorCode.CANNOT_SLICE_BLOB, 'Cannot slice blob for upload. Please retry the upload.' ); } -export function serverFileWrongSize(): FirebaseStorageError { - return new FirebaseStorageError( +export function serverFileWrongSize(): StorageError { + return new StorageError( StorageErrorCode.SERVER_FILE_WRONG_SIZE, 'Server recorded incorrect upload file size, please retry the upload.' ); } -export function noDownloadURL(): FirebaseStorageError { - return new FirebaseStorageError( +export function noDownloadURL(): StorageError { + return new StorageError( StorageErrorCode.NO_DOWNLOAD_URL, 'The given file does not have any download URLs.' ); @@ -253,8 +253,8 @@ export function noDownloadURL(): FirebaseStorageError { /** * @internal */ -export function invalidArgument(message: string): FirebaseStorageError { - return new FirebaseStorageError(StorageErrorCode.INVALID_ARGUMENT, message); +export function invalidArgument(message: string): StorageError { + return new StorageError(StorageErrorCode.INVALID_ARGUMENT, message); } export function invalidArgumentCount( @@ -262,7 +262,7 @@ export function invalidArgumentCount( argMax: number, fnName: string, real: number -): FirebaseStorageError { +): StorageError { let countPart; let plural; if (argMin === argMax) { @@ -272,7 +272,7 @@ export function invalidArgumentCount( countPart = 'between ' + argMin + ' and ' + argMax; plural = 'arguments'; } - return new FirebaseStorageError( + return new StorageError( StorageErrorCode.INVALID_ARGUMENT_COUNT, 'Invalid argument count in `' + fnName + @@ -286,8 +286,8 @@ export function invalidArgumentCount( ); } -export function appDeleted(): FirebaseStorageError { - return new FirebaseStorageError( +export function appDeleted(): StorageError { + return new StorageError( StorageErrorCode.APP_DELETED, 'The Firebase app was deleted.' ); @@ -298,8 +298,8 @@ export function appDeleted(): FirebaseStorageError { * * @internal */ -export function invalidRootOperation(name: string): FirebaseStorageError { - return new FirebaseStorageError( +export function invalidRootOperation(name: string): StorageError { + return new StorageError( StorageErrorCode.INVALID_ROOT_OPERATION, "The operation '" + name + @@ -315,8 +315,8 @@ export function invalidRootOperation(name: string): FirebaseStorageError { export function invalidFormat( format: string, message: string -): FirebaseStorageError { - return new FirebaseStorageError( +): StorageError { + return new StorageError( StorageErrorCode.INVALID_FORMAT, "String does not match format '" + format + "': " + message ); @@ -325,8 +325,8 @@ export function invalidFormat( /** * @param message - A message describing the internal error. */ -export function unsupportedEnvironment(message: string): FirebaseStorageError { - throw new FirebaseStorageError( +export function unsupportedEnvironment(message: string): StorageError { + throw new StorageError( StorageErrorCode.UNSUPPORTED_ENVIRONMENT, message ); @@ -335,8 +335,8 @@ export function unsupportedEnvironment(message: string): FirebaseStorageError { /** * @param message - A message describing the internal error. */ -export function internalError(message: string): FirebaseStorageError { - throw new FirebaseStorageError( +export function internalError(message: string): StorageError { + throw new StorageError( StorageErrorCode.INTERNAL_ERROR, 'Internal error: ' + message ); diff --git a/packages/storage/src/implementation/failrequest.ts b/packages/storage/src/implementation/failrequest.ts index afd4cd12ec4..018b543862b 100644 --- a/packages/storage/src/implementation/failrequest.ts +++ b/packages/storage/src/implementation/failrequest.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { FirebaseStorageError } from './error'; +import { StorageError } from './error'; import { Request } from './request'; /** @@ -23,7 +23,7 @@ import { Request } from './request'; export class FailRequest implements Request { promise_: Promise; - constructor(error: FirebaseStorageError) { + constructor(error: StorageError) { this.promise_ = Promise.reject(error); } diff --git a/packages/storage/src/implementation/fs.ts b/packages/storage/src/implementation/fs.ts index 973ab70cfb3..2dc86617eac 100644 --- a/packages/storage/src/implementation/fs.ts +++ b/packages/storage/src/implementation/fs.ts @@ -20,7 +20,7 @@ * bloats the size of the released binary. */ import { isNativeBlobDefined } from './type'; -import { StorageErrorCode, FirebaseStorageError } from './error'; +import { StorageErrorCode, StorageError } from './error'; function getBlobBuilder(): typeof IBlobBuilder | undefined { if (typeof BlobBuilder !== 'undefined') { @@ -50,7 +50,7 @@ export function getBlob(...args: Array): Blob { if (isNativeBlobDefined()) { return new Blob(args); } else { - throw new FirebaseStorageError( + throw new StorageError( StorageErrorCode.UNSUPPORTED_ENVIRONMENT, "This browser doesn't seem to support creating Blobs" ); diff --git a/packages/storage/src/implementation/observer.ts b/packages/storage/src/implementation/observer.ts index d1ab432610d..ef5daab156f 100644 --- a/packages/storage/src/implementation/observer.ts +++ b/packages/storage/src/implementation/observer.ts @@ -15,7 +15,7 @@ * limitations under the License. */ import { isFunction } from './type'; -import { FirebaseStorageError } from './error'; +import { StorageError } from './error'; /** * Function that is called once for each value in a stream of values. @@ -23,10 +23,10 @@ import { FirebaseStorageError } from './error'; export type NextFn = (value: T) => void; /** - * A function that is called with a `FirebaseStorageError` + * A function that is called with a `StorageError` * if the event stream ends due to an error. */ -export type ErrorFn = (error: FirebaseStorageError) => void; +export type ErrorFn = (error: StorageError) => void; /** * A function that is called if the event stream ends normally. @@ -40,7 +40,7 @@ export type Unsubscribe = () => void; /** * An observer identical to the `Observer` defined in packages/util except the - * error passed into the ErrorFn is specifically a `FirebaseStorageError`. + * error passed into the ErrorFn is specifically a `StorageError`. */ export interface StorageObserver { /** @@ -48,7 +48,7 @@ export interface StorageObserver { */ next?: NextFn; /** - * A function that is called with a `FirebaseStorageError` + * A function that is called with a `StorageError` * if the event stream ends due to an error. */ error?: ErrorFn; diff --git a/packages/storage/src/implementation/request.ts b/packages/storage/src/implementation/request.ts index 1d374c6e609..e7beb9dd5a4 100644 --- a/packages/storage/src/implementation/request.ts +++ b/packages/storage/src/implementation/request.ts @@ -22,7 +22,7 @@ import { start, stop, id as backoffId } from './backoff'; import { - FirebaseStorageError, + StorageError, unknown, appDeleted, canceled, @@ -63,7 +63,7 @@ class NetworkRequest implements Request { private appDelete_: boolean = false; private callback_: (p1: Connection, p2: string) => T; private errorCallback_: - | ((p1: Connection, p2: FirebaseStorageError) => FirebaseStorageError) + | ((p1: Connection, p2: StorageError) => StorageError) | null; private progressCallback_: ((p1: number, p2: number) => void) | null; private timeout_: number; @@ -79,7 +79,7 @@ class NetworkRequest implements Request { additionalRetryCodes: number[], callback: (p1: Connection, p2: string) => T, errorCallback: - | ((p1: Connection, p2: FirebaseStorageError) => FirebaseStorageError) + | ((p1: Connection, p2: StorageError) => StorageError) | null, timeout: number, progressCallback: ((p1: number, p2: number) => void) | null, diff --git a/packages/storage/src/implementation/requestinfo.ts b/packages/storage/src/implementation/requestinfo.ts index 924d81b51f8..1b9b4ab308a 100644 --- a/packages/storage/src/implementation/requestinfo.ts +++ b/packages/storage/src/implementation/requestinfo.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { FirebaseStorageError } from './error'; +import { StorageError } from './error'; import { Headers, Connection } from './connection'; /** @@ -30,7 +30,7 @@ export class RequestInfo { body: Blob | string | Uint8Array | null = null; errorHandler: - | ((p1: Connection, p2: FirebaseStorageError) => FirebaseStorageError) + | ((p1: Connection, p2: StorageError) => StorageError) | null = null; /** diff --git a/packages/storage/src/implementation/requests.ts b/packages/storage/src/implementation/requests.ts index 1282ac7ab8c..36a5287e52b 100644 --- a/packages/storage/src/implementation/requests.ts +++ b/packages/storage/src/implementation/requests.ts @@ -23,7 +23,7 @@ import { Metadata } from '../metadata'; import { ListResult } from '../list'; import { FbsBlob } from './blob'; import { - FirebaseStorageError, + StorageError, cannotSliceBlob, unauthenticated, quotaExceeded, @@ -48,7 +48,7 @@ import { Connection } from './connection'; import { FirebaseStorageImpl } from '../service'; /** - * Throws the UNKNOWN FirebaseStorageError if cndn is false. + * Throws the UNKNOWN StorageError if cndn is false. */ export function handlerCheck(cndn: boolean): void { if (!cndn) { @@ -98,11 +98,11 @@ export function downloadUrlHandler( export function sharedErrorHandler( location: Location -): (p1: Connection, p2: FirebaseStorageError) => FirebaseStorageError { +): (p1: Connection, p2: StorageError) => StorageError { function errorHandler( xhr: Connection, - err: FirebaseStorageError - ): FirebaseStorageError { + err: StorageError + ): StorageError { let newErr; if (xhr.getStatus() === 401) { if ( @@ -133,13 +133,13 @@ export function sharedErrorHandler( export function objectErrorHandler( location: Location -): (p1: Connection, p2: FirebaseStorageError) => FirebaseStorageError { +): (p1: Connection, p2: StorageError) => StorageError { const shared = sharedErrorHandler(location); function errorHandler( xhr: Connection, - err: FirebaseStorageError - ): FirebaseStorageError { + err: StorageError + ): StorageError { let newErr = shared(xhr, err); if (xhr.getStatus() === 404) { newErr = objectNotFound(location.path); diff --git a/packages/storage/src/implementation/string.ts b/packages/storage/src/implementation/string.ts index 8497190389f..0462576128c 100644 --- a/packages/storage/src/implementation/string.ts +++ b/packages/storage/src/implementation/string.ts @@ -22,7 +22,7 @@ import { decodeBase64 } from '../platform/base64'; * An enumeration of the possible string formats for upload. * @public */ -export type StringFormat = string; +export type StringFormat = typeof StringFormat[keyof typeof StringFormat]; /** * An enumeration of the possible string formats for upload. * @public @@ -60,7 +60,7 @@ export const StringFormat = { * be overridden in the metadata object). */ DATA_URL: 'data_url' -}; +} as const; export class StringData { contentType: string | null; diff --git a/packages/storage/src/public-types.ts b/packages/storage/src/public-types.ts index b2890cf0bfc..7d14bf0fe06 100644 --- a/packages/storage/src/public-types.ts +++ b/packages/storage/src/public-types.ts @@ -253,7 +253,7 @@ export type TaskState = 'running' | 'paused' | 'success' | 'canceled' | 'error'; * An error returned by the Firebase Storage SDK. * @public */ -export interface FirebaseStorageError extends FirebaseError { +export interface StorageError extends FirebaseError { /** * A server response message for the error, if applicable. */ @@ -266,7 +266,7 @@ export interface FirebaseStorageError extends FirebaseError { */ export interface StorageObserver { next?: NextFn | null; - error?: (error: FirebaseStorageError) => void | null; + error?: (error: StorageError) => void | null; complete?: CompleteFn | null; } @@ -284,7 +284,7 @@ export interface UploadTask { /** * Equivalent to calling `then(null, onRejected)`. */ - catch(onRejected: (error: FirebaseStorageError) => unknown): Promise; + catch(onRejected: (error: StorageError) => unknown): Promise; /** * Listens for events on this task. * @@ -384,7 +384,7 @@ export interface UploadTask { * The `next` function, which gets called for each item in * the event stream, or an observer object with some or all of these three * properties (`next`, `error`, `complete`). - * @param error - A function that gets called with a `FirebaseStorageError` + * @param error - A function that gets called with a `StorageError` * if the event stream ends due to an error. * @param completed - A function that gets called if the * event stream ends normally. @@ -400,7 +400,7 @@ export interface UploadTask { | StorageObserver | null | ((snapshot: UploadTaskSnapshot) => unknown), - error?: ((a: FirebaseStorageError) => unknown) | null, + error?: ((a: StorageError) => unknown) | null, complete?: Unsubscribe | null ): Unsubscribe | Subscribe; @@ -428,7 +428,7 @@ export interface UploadTask { */ then( onFulfilled?: ((snapshot: UploadTaskSnapshot) => unknown) | null, - onRejected?: ((error: FirebaseStorageError) => unknown) | null + onRejected?: ((error: StorageError) => unknown) | null ): Promise; } diff --git a/packages/storage/src/task.ts b/packages/storage/src/task.ts index 04c58d4ca1f..91131f63615 100644 --- a/packages/storage/src/task.ts +++ b/packages/storage/src/task.ts @@ -22,7 +22,7 @@ import { FbsBlob } from './implementation/blob'; import { canceled, StorageErrorCode, - FirebaseStorageError + StorageError } from './implementation/error'; import { InternalTaskState, @@ -81,14 +81,14 @@ export class UploadTask { * Upload state. */ _state: InternalTaskState; - private _error?: FirebaseStorageError = undefined; + private _error?: StorageError = undefined; private _uploadUrl?: string = undefined; private _request?: Request = undefined; private _chunkMultiplier: number = 1; - private _errorHandler: (p1: FirebaseStorageError) => void; - private _metadataErrorHandler: (p1: FirebaseStorageError) => void; + private _errorHandler: (p1: StorageError) => void; + private _metadataErrorHandler: (p1: StorageError) => void; private _resolve?: (p1: UploadTaskSnapshot) => void = undefined; - private _reject?: (p1: FirebaseStorageError) => void = undefined; + private _reject?: (p1: StorageError) => void = undefined; private _promise: Promise; /** @@ -468,7 +468,7 @@ export class UploadTask { * The `next` function, which gets called for each item in * the event stream, or an observer object with some or all of these three * properties (`next`, `error`, `complete`). - * @param error - A function that gets called with a `FirebaseStorageError` + * @param error - A function that gets called with a `StorageError` * if the event stream ends due to an error. * @param completed - A function that gets called if the * event stream ends normally. @@ -484,7 +484,7 @@ export class UploadTask { | StorageObserver | null | ((snapshot: UploadTaskSnapshot) => unknown), - error?: ((a: FirebaseStorageError) => unknown) | null, + error?: ((a: StorageError) => unknown) | null, completed?: Unsubscribe | null ): Unsubscribe | Subscribe { const observer = new Observer( @@ -508,7 +508,7 @@ export class UploadTask { */ then( onFulfilled?: ((value: UploadTaskSnapshot) => U | Promise) | null, - onRejected?: ((error: FirebaseStorageError) => U | Promise) | null + onRejected?: ((error: StorageError) => U | Promise) | null ): Promise { // These casts are needed so that TypeScript can infer the types of the // resulting Promise. @@ -522,7 +522,7 @@ export class UploadTask { * Equivalent to calling `then(null, onRejected)`. */ catch( - onRejected: (p1: FirebaseStorageError) => T | Promise + onRejected: (p1: StorageError) => T | Promise ): Promise { return this.then(null, onRejected); } @@ -562,8 +562,8 @@ export class UploadTask { break; case TaskState.CANCELED: case TaskState.ERROR: - const toCall = this._reject as (p1: FirebaseStorageError) => void; - fbsAsync(toCall.bind(null, this._error as FirebaseStorageError))(); + const toCall = this._reject as (p1: StorageError) => void; + fbsAsync(toCall.bind(null, this._error as StorageError))(); break; default: triggered = false; @@ -594,7 +594,7 @@ export class UploadTask { case TaskState.ERROR: if (observer.error) { fbsAsync( - observer.error.bind(observer, this._error as FirebaseStorageError) + observer.error.bind(observer, this._error as StorageError) )(); } break; @@ -602,7 +602,7 @@ export class UploadTask { // TODO(andysoto): assert(false); if (observer.error) { fbsAsync( - observer.error.bind(observer, this._error as FirebaseStorageError) + observer.error.bind(observer, this._error as StorageError) )(); } } diff --git a/packages/storage/test/unit/connection.ts b/packages/storage/test/unit/connection.ts index b63dbdcb10e..350feaa90bf 100644 --- a/packages/storage/test/unit/connection.ts +++ b/packages/storage/test/unit/connection.ts @@ -20,7 +20,7 @@ import { Connection } from '../../src/implementation/connection'; import { - FirebaseStorageError, + StorageError, StorageErrorCode } from '../../src/implementation/error'; @@ -67,7 +67,7 @@ export class TestingConnection implements Connection { headers?: Headers ): Promise { if (this.state !== State.START) { - throw new FirebaseStorageError( + throw new StorageError( StorageErrorCode.UNKNOWN, "Can't send again" ); @@ -87,7 +87,7 @@ export class TestingConnection implements Connection { headers: { [key: string]: string } ): void { if (this.state !== State.SENT) { - throw new FirebaseStorageError( + throw new StorageError( StorageErrorCode.UNKNOWN, "Can't simulate response before send/more than once" ); diff --git a/packages/storage/test/unit/service.test.ts b/packages/storage/test/unit/service.test.ts index 423eb732f8a..9e588cafbf7 100644 --- a/packages/storage/test/unit/service.test.ts +++ b/packages/storage/test/unit/service.test.ts @@ -25,7 +25,7 @@ import { } from '../../src/service'; import * as testShared from './testshared'; import { DEFAULT_HOST } from '../../src/implementation/constants'; -import { FirebaseStorageError } from '../../src/implementation/error'; +import { StorageError } from '../../src/implementation/error'; import { Reference, getMetadata, @@ -402,8 +402,8 @@ GOOG4-RSA-SHA256` uploadBytesResumable(reference, new Uint8Array([97])).on( TaskEvent.STATE_CHANGED, undefined, - (err: FirebaseStorageError | Error) => { - expect((err as FirebaseStorageError).code).to.equal( + (err: StorageError | Error) => { + expect((err as StorageError).code).to.equal( 'storage/app-deleted' ); resolve(); diff --git a/packages/storage/test/unit/testshared.ts b/packages/storage/test/unit/testshared.ts index 338ccdb9e53..b0c368e87d4 100644 --- a/packages/storage/test/unit/testshared.ts +++ b/packages/storage/test/unit/testshared.ts @@ -21,7 +21,7 @@ use(chaiAsPromised); import { FirebaseApp } from '@firebase/app-types'; import { CONFIG_STORAGE_BUCKET_KEY } from '../../src/implementation/constants'; -import { FirebaseStorageError } from '../../src/implementation/error'; +import { StorageError } from '../../src/implementation/error'; import { Headers, Connection } from '../../src/implementation/connection'; import { ConnectionPool } from '../../src/implementation/connectionPool'; import { SendHook, TestingConnection } from './connection'; @@ -155,8 +155,8 @@ export function bind(f: Function, ctx: any, ...args: any[]): () => void { export function assertThrows( f: () => void, code: string -): FirebaseStorageError { - let captured: FirebaseStorageError | null = null; +): StorageError { + let captured: StorageError | null = null; expect(() => { try { f(); @@ -168,11 +168,11 @@ export function assertThrows( // @ts-ignore Compiler does not know callback is invoked immediately and // thinks catch block is unreachable. This is an open TS issue: // https://github.com/microsoft/TypeScript/issues/11498 - expect(captured).to.be.an.instanceof(FirebaseStorageError); + expect(captured).to.be.an.instanceof(StorageError); // @ts-ignore See above. expect(captured.code).to.equal(code); // @ts-ignore See above. - return captured as FirebaseStorageError; + return captured as StorageError; } export function assertUint8ArrayEquals(