seed
This commit is contained in:
parent
019a6c433d
commit
8564747a82
@ -2,8 +2,10 @@ import Koa from "koa";
|
||||
import router from "./routers/router";
|
||||
import bodyParser from "koa-bodyparser";
|
||||
import InitHandler from "./routers/handler";
|
||||
import catchError from "./utils/catchError";
|
||||
// 使用路由
|
||||
const app = new Koa();
|
||||
app.use(catchError);
|
||||
app.use(bodyParser());
|
||||
|
||||
|
||||
|
12
src/utils/catchError.ts
Normal file
12
src/utils/catchError.ts
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
const catchError = async (ctx: any, next: any) => {
|
||||
try {
|
||||
await next();
|
||||
} catch (error:any) {
|
||||
if (error.errorCode) {
|
||||
console.log("捕获到异常")
|
||||
return ctx.body = error.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
export default catchError;
|
Loading…
x
Reference in New Issue
Block a user