Files
esign/packages/lib/utils/render-email-with-i18n.tsx
zeekayandHanzo Dev 87f33903e2 fix(lint): keep the caught error as the cause of the one rethrown
ESLint 10's recommended set added preserve-caught-error: a catch block that
throws a new error has to pass the caught one as its cause. Five places
caught an error and threw a plainer one in its place — fetching the OIDC
configuration, sending a confirmation email, triggering a webhook,
validating a Zapier API token, rendering an email — and each failed the
lint.

Each now passes `{ cause: err }`. The thrown error keeps its message and
type; what it gains is the original, which Node prints after it as
`[cause]`. render-email-with-i18n.tsx also loses its stale ban-types
disable comment, as the five files in the commit before did.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-19 05:02:03 -07:00

32 lines
902 B
TypeScript

import type { RenderOptions } from '@hanzo/esign-email/render';
import { renderWithI18N } from '@hanzo/esign-email/render';
import { getI18nInstance } from '../client-only/providers/i18n-server';
import {
APP_I18N_OPTIONS,
type SupportedLanguageCodes,
isValidLanguageCode,
} from '../constants/i18n';
export const renderEmailWithI18N = async (
component: React.ReactElement,
options?: RenderOptions & {
lang?: SupportedLanguageCodes | (string & {});
},
) => {
try {
const { lang: providedLang, ...otherOptions } = options ?? {};
const lang = isValidLanguageCode(providedLang) ? providedLang : APP_I18N_OPTIONS.sourceLang;
const i18n = await getI18nInstance(lang);
i18n.activate(lang);
return renderWithI18N(component, { i18n, ...otherOptions });
} catch (err) {
console.error(err);
throw new Error('Failed to render email', { cause: err });
}
};