mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
refactor(http): inline serveFallback()
util (#5917)
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
parent
fb79076121
commit
70f981e605
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user