@exabytellc/utils
Version:
EB react utils to make everything a little easier!
28 lines (27 loc) • 879 B
JavaScript
import { validParam } from "./handleError";
export default class ClassHelper {
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);
}
handleTryCatch = ClassHelper.handleTryCatch;
handleTryCatchAsync = ClassHelper.handleTryCatchAsync;
handleError = ClassHelper.handleError;
}