0
Fork 0
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:
bholmesdev 2024-08-02 17:34:12 -04:00 committed by bholmesdev
parent 7546001cab
commit 4ce97194a6

View file

@ -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 });
}