mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -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({
|
async function redirectWithResult({
|
||||||
context,
|
context,
|
||||||
next,
|
|
||||||
actionName,
|
actionName,
|
||||||
actionResult,
|
actionResult,
|
||||||
}: {
|
}: {
|
||||||
context: APIContext;
|
context: APIContext;
|
||||||
next: MiddlewareNext;
|
|
||||||
actionName: string;
|
actionName: string;
|
||||||
actionResult: SafeResult<any, any>;
|
actionResult: SafeResult<any, any>;
|
||||||
}) {
|
}) {
|
||||||
|
@ -146,7 +144,9 @@ async function redirectWithResult({
|
||||||
|
|
||||||
if (actionResult.error) {
|
if (actionResult.error) {
|
||||||
const referer = context.request.headers.get('Referer');
|
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);
|
return context.redirect(referer);
|
||||||
}
|
}
|
||||||
|
@ -183,5 +183,5 @@ async function handlePostLegacy({ context, next }: { context: APIContext; next:
|
||||||
|
|
||||||
const action = baseAction.bind(context);
|
const action = baseAction.bind(context);
|
||||||
const actionResult = await action(formData);
|
const actionResult = await action(formData);
|
||||||
return redirectWithResult({ context, next, actionName, actionResult });
|
return redirectWithResult({ context, actionName, actionResult });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue