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