mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
refactor: next() -> throw internal error
This commit is contained in:
parent
7546001cab
commit
4ce97194a6
1 changed files with 5 additions and 5 deletions
|
@ -124,17 +124,15 @@ async function handlePost({
|
|||
});
|
||||
}
|
||||
|
||||
return redirectWithResult({ context, next, actionName, actionResult });
|
||||
return redirectWithResult({ context, actionName, actionResult });
|
||||
}
|
||||
|
||||
async function redirectWithResult({
|
||||
context,
|
||||
next,
|
||||
actionName,
|
||||
actionResult,
|
||||
}: {
|
||||
context: APIContext;
|
||||
next: MiddlewareNext;
|
||||
actionName: string;
|
||||
actionResult: SafeResult<any, any>;
|
||||
}) {
|
||||
|
@ -146,7 +144,9 @@ async function redirectWithResult({
|
|||
|
||||
if (actionResult.error) {
|
||||
const referer = context.request.headers.get('Referer');
|
||||
if (!referer) return next();
|
||||
if (!referer) {
|
||||
throw new Error('Internal: Referer unexpectedly missing from Action POST request.');
|
||||
}
|
||||
|
||||
return context.redirect(referer);
|
||||
}
|
||||
|
@ -183,5 +183,5 @@ async function handlePostLegacy({ context, next }: { context: APIContext; next:
|
|||
|
||||
const action = baseAction.bind(context);
|
||||
const actionResult = await action(formData);
|
||||
return redirectWithResult({ context, next, actionName, actionResult });
|
||||
return redirectWithResult({ context, actionName, actionResult });
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue