UNPKG

@funnelenvy-npm/fe-dev-utils

Version:

Helper function to build client side A/B tests

34 lines (33 loc) 1.4 kB
"use strict"; /** * Function for sending error messages to the backend * @param {Object} options - Options object to configure the function. * @param {Object} options.error - Error object to log to the backend. * @param {string} [options.activity] - Name of the activity that triggered the error. * * Global Window Extensions: * @property {Object} [window.FeActivityLoader] - An object to detect the environment type. * @property {function} [window.FeActivityLoader.detectTypeOfEnvironment] - Returns the current environment type (e.g., "PROD"). * @property {Object} [window.headerData] - Contains user-related metadata. */ Object.defineProperty(exports, "__esModule", { value: true }); const onError = ({ activity, error, }) => { try { if (error && window?.FeActivityLoader?.detectTypeOfEnvironment() === "PROD") { fetch("https://funnelenvy.retool.com/url/error-logging", { method: "POST", mode: "cors", body: JSON.stringify({ message: error?.message ?? error ?? "", location: window.location.href, activity, customer: window?.headerData?.user?.account_id ?? "", stack_trace: error?.stack ?? error ?? null, }), }); } } catch (e) { } }; exports.default = onError;