Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/flat-chicken-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

'astro': patch
---

Improves the `UnsupportedExternalRedirect` error message to include more details such as the concerned destination
3 changes: 2 additions & 1 deletion packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,8 @@ export const RedirectWithNoLocation = {
export const UnsupportedExternalRedirect = {
name: 'UnsupportedExternalRedirect',
title: 'Unsupported or malformed URL.',
message: 'An external redirect must start with http or https, and must be a valid URL.',
message: (from: string, to: string) => `The external redirect from "${from}" to "${to}" is invalid.`,
hint: 'An external redirect must start with http or https, and must be a valid URL.',
} satisfies ErrorData;

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ function createRedirectRoutes(

// check if the link starts with http or https; if not, throw an error
if (URL.canParse(destination) && !/^https?:\/\//.test(destination)) {
throw new AstroError(UnsupportedExternalRedirect);
throw new AstroError({
...UnsupportedExternalRedirect,
message: UnsupportedExternalRedirect.message(from, destination),
});
}

routes.push({
Expand Down
Loading