feat(ui): more context in storage errors

This commit is contained in:
psychedelicious 2024-01-11 20:27:53 +11:00
parent 630854ce26
commit 07416753be
2 changed files with 18 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import { StorageError } from 'app/store/enhancers/reduxRemember/errors';
import { $projectId } from 'app/store/nanostores/projectId';
import type { UseStore } from 'idb-keyval';
import {
clear,
@ -24,14 +25,23 @@ export const idbKeyValDriver: Driver = {
try {
return get(key, $idbKeyValStore.get());
} catch (originalError) {
throw new StorageError({ key, originalError });
throw new StorageError({
key,
projectId: $projectId.get(),
originalError,
});
}
},
setItem: (key, value) => {
try {
return set(key, value, $idbKeyValStore.get());
} catch (originalError) {
throw new StorageError({ key, value, originalError });
throw new StorageError({
key,
value,
projectId: $projectId.get(),
originalError,
});
}
},
};

View File

@ -8,6 +8,7 @@ export type StorageErrorArgs = {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ // any is correct
value?: any;
originalError?: unknown;
projectId?: string;
};
export class StorageError extends Error {
@ -15,14 +16,18 @@ export class StorageError extends Error {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ // any is correct
value?: any;
originalError?: Error;
projectId?: string;
constructor({ key, value, originalError }: StorageErrorArgs) {
constructor({ key, value, originalError, projectId }: StorageErrorArgs) {
super(`Error setting ${key}`);
this.name = 'StorageSetError';
this.key = key;
if (value !== undefined) {
this.value = value;
}
if (projectId !== undefined) {
this.projectId = projectId;
}
if (originalError instanceof Error) {
this.originalError = originalError;
}