feat: ignore error

This commit is contained in:
monoid 2023-06-12 10:36:33 +09:00
parent 073bc9f8e3
commit a208c40e06

22
app.ts
View File

@ -1,4 +1,4 @@
import { Application, Router } from "https://deno.land/x/oak@v12.1.0/mod.ts";
import { Application, Router, isHttpError } from "https://deno.land/x/oak@v12.1.0/mod.ts";
import {
searchRepositoryWithTopic,
getRepositoryTags,
@ -123,13 +123,29 @@ router.get("/:package([a-z0-9_]*@[a-z0-9_]*)/:version?/:path*", async (ctx) => {
}
});
app.use(router.routes());
app.use(router.allowedMethods());
app.use(async (ctx, next) => {
try{
await next();
}
catch (err) {
console.log(err);
if (isHttpError(err)) {
ctx.response.status = err.status;
const { message, status, stack } = err;
ctx.response.body = { message, status, stack };
}
else { throw err;
}
}
});
//app.use(async (ctx, next) => {
// ctx.throw(404);
// //ctx.response.status = 404;
// //ctx.response.body = "Not Found";
// //await next();
//});