fix: global error handler for js package (#1863)

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
Anshuman Pandey
2024-01-10 22:03:18 +05:30
committed by GitHub
parent 0534421538
commit 8002d3e71f
6 changed files with 45 additions and 12 deletions

View File

@@ -111,8 +111,7 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
},
{
name: "Langfuse",
description:
"Open source LLM engineering platform. Debug, analyze and iterate together.",
description: "Open source LLM engineering platform. Debug, analyze and iterate together.",
href: "https://langfuse.com",
},
{

View File

@@ -1,7 +1,8 @@
import { cn } from "@formbricks/lib/cn";
import { PresentationChartLineIcon, InboxStackIcon } from "@heroicons/react/24/solid";
import Link from "next/link";
import revalidateSurveyIdPath from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/actions";
import { InboxStackIcon, PresentationChartLineIcon } from "@heroicons/react/24/solid";
import Link from "next/link";
import { cn } from "@formbricks/lib/cn";
interface SurveyResultsTabProps {
activeId: string;

View File

@@ -1,11 +1,13 @@
"use server";
import { createTag } from "@formbricks/lib/tag/service";
import { addTagToRespone, deleteTagOnResponse } from "@formbricks/lib/tagOnResponse/service";
import { hasUserEnvironmentAccess } from "@formbricks/lib/environment/auth";
import { authOptions } from "@formbricks/lib/authOptions";
import { getServerSession } from "next-auth";
import { AuthorizationError } from "@formbricks/types/errors";
import { authOptions } from "@formbricks/lib/authOptions";
import { hasUserEnvironmentAccess } from "@formbricks/lib/environment/auth";
import { createTag } from "@formbricks/lib/tag/service";
import { canUserAccessTagOnResponse } from "@formbricks/lib/tagOnResponse/auth";
import { addTagToRespone, deleteTagOnResponse } from "@formbricks/lib/tagOnResponse/service";
import { AuthorizationError } from "@formbricks/types/errors";
export const createTagAction = async (environmentId: string, tagName: string) => {
const session = await getServerSession(authOptions);

View File

@@ -1,3 +1,5 @@
import { wrapThrowsAsync } from "@formbricks/types/errorHandlers";
import { ErrorHandler, Result } from "./errors";
import { checkInitialized } from "./initialize";
@@ -47,11 +49,23 @@ export class CommandQueue {
if (initResult && initResult.ok !== true) errorHandler.handle(initResult.error);
}
const result = (await currentItem?.command.apply(null, currentItem?.commandArgs)) as Result<void, any>;
const executeCommand = async () => {
return (await currentItem?.command.apply(null, currentItem?.commandArgs)) as Result<void, any>;
};
const result = await wrapThrowsAsync(executeCommand)();
if (!result) continue;
if (result.ok !== true) errorHandler.handle(result.error);
if (result.ok) {
if (!result.data.ok) {
errorHandler.handle(result.data.error);
}
}
if (result.ok !== true) {
errorHandler.handle(result.error);
}
}
this.running = false;
if (this.resolvePromise) {

View File

@@ -132,6 +132,7 @@ export class ErrorHandler {
}
public handle(error: any): void {
console.warn("🧱 Formbricks - Global error: ", error);
this.handleError(error);
}
}

View File

@@ -123,3 +123,19 @@ export const wrapThrows =
};
}
};
export const wrapThrowsAsync =
<T, A extends any[]>(fn: (...args: A) => Promise<T>) =>
async (...args: A): Promise<Result<T>> => {
try {
return {
ok: true,
data: await fn(...args),
};
} catch (error) {
return {
ok: false,
error: error as Error,
};
}
};