From 28ee87cd2f238cc646963a1b2021dd9157d93c0b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 9 Aug 2021 19:24:09 -0700 Subject: [PATCH] Migrate error.js to TypeScript --- src/matrix/storage/idb/Store.js | 2 +- src/matrix/storage/idb/{error.js => error.ts} | 11 +++++++---- src/matrix/storage/idb/utils.ts | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) rename src/matrix/storage/idb/{error.js => error.ts} (84%) diff --git a/src/matrix/storage/idb/Store.js b/src/matrix/storage/idb/Store.js index 2cafe500..91617b5f 100644 --- a/src/matrix/storage/idb/Store.js +++ b/src/matrix/storage/idb/Store.js @@ -15,7 +15,7 @@ limitations under the License. */ import {QueryTarget} from "./QueryTarget.js"; -import {IDBRequestAttemptError} from "./error.js"; +import {IDBRequestAttemptError} from "./error"; const LOG_REQUESTS = false; diff --git a/src/matrix/storage/idb/error.js b/src/matrix/storage/idb/error.ts similarity index 84% rename from src/matrix/storage/idb/error.js rename to src/matrix/storage/idb/error.ts index 0b9de95c..02953886 100644 --- a/src/matrix/storage/idb/error.js +++ b/src/matrix/storage/idb/error.ts @@ -18,7 +18,10 @@ limitations under the License. import { StorageError } from "../common"; export class IDBError extends StorageError { - constructor(message, source, cause) { + storeName: string; + databaseName: string; + + constructor(message: string, source, cause: DOMException | null) { const storeName = source?.name || ""; const databaseName = source?.transaction?.db?.name || ""; let fullMessage = `${message} on ${databaseName}.${storeName}`; @@ -34,14 +37,14 @@ export class IDBError extends StorageError { if (cause) { fullMessage += cause.message; } - super(fullMessage, cause); + super(fullMessage, cause || undefined); this.storeName = storeName; this.databaseName = databaseName; } } export class IDBRequestError extends IDBError { - constructor(request, message = "IDBRequest failed") { + constructor(request: IDBRequest, message: string = "IDBRequest failed") { const source = request.source; const cause = request.error; super(message, source, cause); @@ -49,7 +52,7 @@ export class IDBRequestError extends IDBError { } export class IDBRequestAttemptError extends IDBError { - constructor(method, source, cause, params) { + constructor(method: string, source, cause: DOMException, params: any[]) { super(`${method}(${params.map(p => JSON.stringify(p)).join(", ")}) failed`, source, cause); } } diff --git a/src/matrix/storage/idb/utils.ts b/src/matrix/storage/idb/utils.ts index 2905eedb..83686864 100644 --- a/src/matrix/storage/idb/utils.ts +++ b/src/matrix/storage/idb/utils.ts @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { IDBRequestError } from "./error.js"; +import { IDBRequestError } from "./error"; import { StorageError } from "../common"; let needsSyncPromise = false;