refactor(http): inline serveFallback() util (#5917)

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Yoshiya Hinosawa 2024-09-05 20:50:25 +09:00 committed by GitHub
parent fb79076121
commit 70f981e605
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -402,18 +402,6 @@ async function serveDirIndex(
});
}
function serveFallback(maybeError: unknown): Response {
if (maybeError instanceof URIError) {
return createStandardResponse(STATUS_CODE.BadRequest);
}
if (maybeError instanceof Deno.errors.NotFound) {
return createStandardResponse(STATUS_CODE.NotFound);
}
return createStandardResponse(STATUS_CODE.InternalServerError);
}
function serverLog(req: Request, status: number) {
const d = new Date().toISOString();
const dateFmt = `[${d.slice(0, 10)} ${d.slice(11, 19)}]`;
@ -650,7 +638,9 @@ export async function serveDir(
response = await createServeDirResponse(req, opts);
} catch (error) {
if (!opts.quiet) logError(error as Error);
response = serveFallback(error);
response = error instanceof Deno.errors.NotFound
? createStandardResponse(STATUS_CODE.NotFound)
: createStandardResponse(STATUS_CODE.InternalServerError);
}
// Do not update the header if the response is a 301 redirect.