Skip to content

Commit 18e1b97

Browse files
fix: improve external redirects message (#13680)
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
1 parent 5f470fd commit 18e1b97

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

.changeset/flat-chicken-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
'astro': patch
3+
---
4+
5+
Improves the `UnsupportedExternalRedirect` error message to include more details such as the concerned destination

packages/astro/src/core/errors/errors-data.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,8 @@ export const RedirectWithNoLocation = {
976976
export const UnsupportedExternalRedirect = {
977977
name: 'UnsupportedExternalRedirect',
978978
title: 'Unsupported or malformed URL.',
979-
message: 'An external redirect must start with http or https, and must be a valid URL.',
979+
message: (from: string, to: string) => `The destination URL in the external redirect from "${from}" to "${to}" is unsupported.`,
980+
hint: 'An external redirect must start with http or https, and must be a valid URL.',
980981
} satisfies ErrorData;
981982

982983
/**

packages/astro/src/core/routing/manifest/create.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,10 @@ function createRedirectRoutes(
359359

360360
// check if the link starts with http or https; if not, throw an error
361361
if (URL.canParse(destination) && !/^https?:\/\//.test(destination)) {
362-
throw new AstroError(UnsupportedExternalRedirect);
362+
throw new AstroError({
363+
...UnsupportedExternalRedirect,
364+
message: UnsupportedExternalRedirect.message(from, destination),
365+
});
363366
}
364367

365368
routes.push({

0 commit comments

Comments
 (0)