@exabytellc/canvas
Version:
EB react canvas!
41 lines • 856 B
JavaScript
import { validParam } from "./handleError";
export default class StorageHelper {
handleTryCatch = StorageHelper.handleTryCatch;
handleTryCatchAsync = StorageHelper.handleTryCatchAsync;
handleError = StorageHelper.handleError;
static handleTryCatch({
n,
k,
c = false,
p,
f = undefined,
e
}) {
try {
validParam(c, p);
return e();
} catch (error) {
this.handleError(n, k, error);
return f;
}
}
static async handleTryCatchAsync({
n,
k,
c = false,
p,
f = undefined,
e
}) {
try {
validParam(c, p);
return await e();
} catch (error) {
this.handleError(n, k, error);
return f;
}
}
static handleError(action, key, error) {
console.error(`Error in ${action} for item "${key}" from ${this.constructor.name}:`, error);
}
}