const ERR_CODE = "apperr000";
const logUnhandledErrors = (logger) => {
  if (!logger) return;
  window.addEventListener(
    "unhandledrejection",
    (event) => {
      logger.fatal({
        errorCode: ERR_CODE,
        message: event.reason?.message || event.reason,
        error: JSON.stringify(event.reason)
      });
    }
  );
  window.addEventListener("error", (event) => {
    const { message, filename = "", lineno = "", colno = "", error } = event;
    if (message.toLowerCase().indexOf("script error") > -1) {
      console.log("Script Error: See Browser Console for Detail");
    } else {
      const logMsg = {
        message,
        filename,
        lineno,
        colno,
        error: JSON.stringify(error)
      };
      logger.fatal({ errorCode: ERR_CODE, ...logMsg });
    }
  });
};
export {
  logUnhandledErrors
};
