mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-15 03:31:26 -05:00
fix: disable formbricks error state in debug mode (#2580)
Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user