feat: ignore error
This commit is contained in:
parent
073bc9f8e3
commit
a208c40e06
22
app.ts
22
app.ts
@ -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();
|
||||
//});
|
||||
|
Loading…
Reference in New Issue
Block a user