Switch errors to using nulls

This commit is contained in:
Danila Fedorin 2021-08-20 10:41:15 -07:00
parent 50b7a8a3fd
commit 0b8acb51a4
2 changed files with 4 additions and 4 deletions

View file

@ -42,9 +42,9 @@ export const STORE_MAP: Readonly<{ [name : string]: string }> = Object.freeze(ST
export class StorageError extends Error { export class StorageError extends Error {
errcode?: string; errcode?: string;
cause?: Error; cause: Error | null;
constructor(message: string, cause?: Error) { constructor(message: string, cause: Error | null = null) {
super(message); super(message);
if (cause) { if (cause) {
this.errcode = cause.name; this.errcode = cause.name;

View file

@ -21,7 +21,7 @@ export class IDBError extends StorageError {
storeName: string; storeName: string;
databaseName: string; databaseName: string;
constructor(message: string, source, cause: DOMException | null) { constructor(message: string, source, cause: DOMException | null = null) {
const storeName = source?.name || "<unknown store>"; const storeName = source?.name || "<unknown store>";
const databaseName = source?.transaction?.db?.name || "<unknown db>"; const databaseName = source?.transaction?.db?.name || "<unknown db>";
let fullMessage = `${message} on ${databaseName}.${storeName}`; let fullMessage = `${message} on ${databaseName}.${storeName}`;
@ -37,7 +37,7 @@ export class IDBError extends StorageError {
if (cause) { if (cause) {
fullMessage += cause.message; fullMessage += cause.message;
} }
super(fullMessage, cause || undefined); super(fullMessage, cause);
this.storeName = storeName; this.storeName = storeName;
this.databaseName = databaseName; this.databaseName = databaseName;
} }