UNPKG

@exabytellc/utils

Version:

EB react utils to make everything a little easier!

28 lines (27 loc) 926 B
import { validParam } from "./handleError"; export default class StorageHelper { 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); } handleTryCatch = StorageHelper.handleTryCatch; handleTryCatchAsync = StorageHelper.handleTryCatchAsync; handleError = StorageHelper.handleError; }