Files
formbricks/apps/web/app/error.tsx
Dhruwang Jariwala a5fa876aa3 feat: refactor translation key management (#6717)
Co-authored-by: Piyush Gupta <piyushguptaa2z123@gmail.com>
Co-authored-by: Piyush Gupta <56182734+gupta-piyush19@users.noreply.github.com>
Co-authored-by: Victor Hugo dos Santos <115753265+victorvhs017@users.noreply.github.com>
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
Co-authored-by: Matti Nannt <matti@formbricks.com>
Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
Co-authored-by: Johannes <johannes@formbricks.com>
Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com>
2025-10-23 14:53:11 +00:00

55 lines
1.7 KiB
TypeScript

"use client";
// Error components must be Client components
import * as Sentry from "@sentry/nextjs";
import { TFunction } from "i18next";
import { useTranslation } from "react-i18next";
import { type ClientErrorType, getClientErrorData } from "@formbricks/types/errors";
import { Button } from "@/modules/ui/components/button";
import { ErrorComponent } from "@/modules/ui/components/error-component";
/**
* Get translated error messages based on error type
*/
const getErrorMessages = (type: ClientErrorType, t: TFunction) => {
if (type === "rate_limit") {
return {
title: t("common.error_rate_limit_title"),
description: t("common.error_rate_limit_description"),
};
}
return {
title: t("common.error_component_title"),
description: t("common.error_component_description"),
};
};
const ErrorBoundary = ({ error, reset }: { error: Error; reset: () => void }) => {
const { t } = useTranslation();
const errorData = getClientErrorData(error);
const { title, description } = getErrorMessages(errorData.type, t);
if (process.env.NODE_ENV === "development") {
console.error(error.message);
} else {
Sentry.captureException(error);
}
return (
<div className="flex h-full w-full flex-col items-center justify-center">
<ErrorComponent title={title} description={description} />
{errorData.showButtons && (
<div className="mt-2">
<Button variant="secondary" onClick={() => reset()} className="mr-2">
{t("common.try_again")}
</Button>
<Button onClick={() => (window.location.href = "/")}>{t("common.go_to_dashboard")}</Button>
</div>
)}
</div>
);
};
export default ErrorBoundary;