@allurereport/web-awesome
Version:
The static files for Allure Awesome Report
24 lines (21 loc) • 666 B
text/typescript
class AllurePersistError extends Error {
constructor(
message: string,
public readonly originalError?: Error,
) {
super(message);
this.name = "AllurePersistError";
}
get message(): string {
return `${this.name}: ${this.message}${this.originalError ? `\n${this.originalError.message}` : ""}`;
}
}
export const persist = <T>(pair: [string, T], storage: Storage = localStorage) => {
const [key, value] = pair;
try {
storage.setItem(key, JSON.stringify(value));
} catch (e) {
// eslint-disable-next-line no-console
console.error(new AllurePersistError(`Failed to persist ${key} to ${storage.name}`, e as Error));
}
};