fix: disable formbricks error state in debug mode (#2580)

Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
This commit is contained in:
Anshuman Pandey
2024-05-14 14:00:18 +05:30
committed by GitHub
parent 5da9091aee
commit fb33005051
2 changed files with 41 additions and 7 deletions

View File

@@ -34,7 +34,8 @@ export const setIsInitialized = (value: boolean) => {
export const initialize = async (
configInput: TJsAppConfigInput
): Promise<Result<void, MissingFieldError | NetworkError | MissingPersonError>> => {
if (getIsDebug()) {
const isDebug = getIsDebug();
if (isDebug) {
logger.configure({ logLevel: "debug" });
}
@@ -53,6 +54,14 @@ export const initialize = async (
// formbricks is in error state, skip initialization
if (existingConfig?.status === "error") {
if (isDebug) {
logger.debug(
"Formbricks is in error state, but debug mode is active. Resetting config and continuing."
);
appConfig.resetConfig();
return okVoid();
}
logger.debug("Formbricks was set to an error state.");
if (existingConfig?.expiresAt && new Date(existingConfig.expiresAt) > new Date()) {
logger.debug("Error state is not expired, skipping initialization");
@@ -150,6 +159,7 @@ export const initialize = async (
} catch (e) {
handleErrorOnFirstInit();
}
// and track the new session event
await trackNoCodeAction("New Session");
}
@@ -181,6 +191,11 @@ export const initialize = async (
};
const handleErrorOnFirstInit = () => {
if (getIsDebug()) {
logger.debug("Not putting formbricks in error state because debug mode is active (no error state)");
return;
}
// put formbricks in error state (by creating a new config) and throw error
const initialErrorConfig: Partial<TJSAppConfig> = {
status: "error",
@@ -212,6 +227,11 @@ export const deinitalize = (): void => {
};
export const putFormbricksInErrorState = (): void => {
if (getIsDebug()) {
logger.debug("Not putting formbricks in error state because debug mode is active (no error state)");
return;
}
logger.debug("Putting formbricks in error state");
// change formbricks status to error
appConfig.update({

View File

@@ -32,7 +32,8 @@ export const setIsInitialized = (value: boolean) => {
export const initialize = async (
configInput: TJsWebsiteConfigInput
): Promise<Result<void, MissingFieldError | NetworkError | MissingPersonError>> => {
if (getIsDebug()) {
const isDebug = getIsDebug();
if (isDebug) {
logger.configure({ logLevel: "debug" });
}
@@ -51,6 +52,14 @@ export const initialize = async (
// formbricks is in error state, skip initialization
if (existingConfig?.status === "error") {
if (isDebug) {
logger.debug(
"Formbricks is in error state, but debug mode is active. Resetting config and continuing."
);
websiteConfig.resetConfig();
return okVoid();
}
logger.debug("Formbricks was set to an error state.");
if (existingConfig?.expiresAt && new Date(existingConfig.expiresAt) > new Date()) {
logger.debug("Error state is not expired, skipping initialization");
@@ -84,11 +93,6 @@ export const initialize = async (
logger.debug("Adding widget container to DOM");
addWidgetContainer();
// let updatedAttributes: TPersonAttributes | null = null;
// if (configInput.attributes) {
// updatedAttributes = { ...configInput.attributes };
// }
if (
existingConfig &&
existingConfig.state &&
@@ -160,6 +164,11 @@ export const initialize = async (
};
const handleErrorOnFirstInit = () => {
if (getIsDebug()) {
logger.debug("Not putting formbricks in error state because debug mode is active (no error state)");
return;
}
// put formbricks in error state (by creating a new config) and throw error
const initialErrorConfig: Partial<TJSAppConfig> = {
status: "error",
@@ -191,6 +200,11 @@ export const deinitalize = (): void => {
};
export const putFormbricksInErrorState = (): void => {
if (getIsDebug()) {
logger.debug("Not putting formbricks in error state because debug mode is active (no error state)");
return;
}
logger.debug("Putting formbricks in error state");
// change formbricks status to error
websiteConfig.update({