Skip to content

Commit 5d83547

Browse files
author
gabriel miranda
committed
feat(preview-server): remove noise from when an email template is not found
1 parent 68fad18 commit 5d83547

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

.changeset/olive-doodles-spend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-email/preview-server": patch
3+
---
4+
5+
improve error messages for when an email template is missing

packages/preview-server/src/actions/get-email-path-from-slug.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,5 @@ export const getEmailPathFromSlug = cache(async (slug: string) => {
2424
return `${pathWithoutExtension}.js`;
2525
}
2626

27-
throw new Error(
28-
`Could not find your email file based on the slug (${slug}) by guessing the file extension. Tried .tsx, .jsx, .ts and .js.
29-
30-
This is most likely not an issue with the preview server. It most likely is that the email doesn't exist.`,
31-
);
27+
return undefined;
3228
});

packages/preview-server/src/app/preview/[...slug]/page.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,9 @@ This is most likely not an issue with the preview server. Maybe there was a typo
5252
);
5353
}
5454

55-
let emailPath: string;
56-
try {
57-
emailPath = await getEmailPathFromSlug(slug);
58-
} catch (exception) {
59-
if (exception instanceof Error) {
60-
console.warn(exception.message);
61-
redirect('/');
62-
}
63-
throw exception;
55+
const emailPath = await getEmailPathFromSlug(slug);
56+
if (!emailPath) {
57+
redirect('/');
6458
}
6559

6660
const serverEmailRenderingResult = await renderEmailByPath(emailPath);

packages/preview-server/src/components/toolbar/resend.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ export function ResendIntegration({
112112

113113
try {
114114
const emailPath = await getEmailPathFromSlug(emailSlug);
115+
if (!emailPath) {
116+
throw new Error(
117+
`Could not find email template that should be at ${emailSlug}`,
118+
);
119+
}
115120
const renderResult = await renderEmailByPath(emailPath);
116121

117122
if ('error' in renderResult) {
@@ -135,10 +140,10 @@ export function ResendIntegration({
135140
prevItems.map((item, index) =>
136141
index === i
137142
? {
138-
...item,
139-
status: 'succeeded',
140-
id: exportResult.data!.id,
141-
}
143+
...item,
144+
status: 'succeeded',
145+
id: exportResult.data!.id,
146+
}
142147
: item,
143148
),
144149
);

packages/preview-server/src/hooks/use-email-rendering-result.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export const useEmailRenderingResult = (
4141
const pathForChangedEmail = await getEmailPathFromSlug(
4242
relativePathForChangedFile,
4343
);
44+
if (!pathForChangedEmail) {
45+
continue;
46+
}
4447

4548
const newRenderingResult = await renderEmailByPath(
4649
pathForChangedEmail,

0 commit comments

Comments
 (0)