Skip to content

Commit 080f404

Browse files
committed
fix: avoid returning API response objects
1 parent 9acee3f commit 080f404

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎src/pages/api/translation.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default async function handler(
1313
res: NextApiResponse
1414
) {
1515
if (req.method !== 'GET') {
16-
return res.status(405).end();
16+
res.status(405).end();
17+
return;
1718
}
1819

1920
const {language, from} = req.query;
@@ -22,15 +23,17 @@ export default async function handler(
2223
language === 'en' ||
2324
!finishedTranslations.includes(language)
2425
) {
25-
return res.status(404).end();
26+
res.status(404).end();
27+
return;
2628
}
2729

2830
const homepage = `https://${language}.react.dev/`;
2931
if (
3032
typeof from !== 'string' ||
3133
!/^\/(?!\/)(?:learn|reference)(?:\/|$)[^\\?#]*$/.test(from)
3234
) {
33-
return res.redirect(302, homepage);
35+
res.redirect(302, homepage);
36+
return;
3437
}
3538

3639
const translatedPage = new URL(from, homepage).toString();
@@ -43,13 +46,14 @@ export default async function handler(
4346
signal: controller.signal,
4447
});
4548
if (response.ok) {
46-
return res.redirect(302, translatedPage);
49+
res.redirect(302, translatedPage);
50+
return;
4751
}
4852
} catch {
4953
// Keep the original homepage behavior when the translation site is unavailable.
5054
} finally {
5155
clearTimeout(timeout);
5256
}
5357

54-
return res.redirect(302, homepage);
58+
res.redirect(302, homepage);
5559
}

0 commit comments

Comments
 (0)