6-4 使用 koa-json-error 进行错误处理是Restful API的第21集视频,该合集共计72集,视频收藏或关注UP主,及时了解更多相关视频内容。
koa-json-error-handler Koa middleware to convert all HTTP error message to JSON response Usage const Koa = require('koa'); const jsonErrorHandler = require('koa-json-error-handler'); const app = new Koa(); app .use(jsonErrorHandler) .listen(8080); app.on('error', (err, ctx) => ...
"koa-json-error": "^3.1.2", "marked": "^0.7.0", "mini-css-extract-plugin": "0.5.0", "normalize.css": "^8.0.1", 1 change: 1 addition & 0 deletions 1 server/package.json Original file line numberDiff line numberDiff line change @@ -15,6 +15,7 @@ "koa": "^2.8.1",...
const error = require('koa-json-error') 在所有中间件之前挂载 //生产环境下不出现错误堆栈信息 app.use( error({ // ES6解构语法 { stack, ...rest } postFormat: (e, { stack, ...rest }) => // process.env.NODE_ENV NODE.JS中获取环境变量的方法 // NODE_ENV为我们定义的(环境变量的名...
一、首先下载koa-json-error依赖 npm i koa-json-error --save 二、在index.js中引入koa-json-error,使用postFormat这个API,传入两个参数一个为原来的错误,一个为自己想定义的返回的对象,然后通过是否为生产环境来判断是否返回stack consterror=require('koa-json-error')app.use(error({postFormat:(e,{stack...
jsonapi (Boolean default: false) will set the response Content-type to application/vnd.api+json and ensure 500 responses are in JSON API format Example: app.use(koaJsonLogger({ name: 'myCoolApp', path: 'logs', jsonapi: true })); When you throw an application error it's best to al...
Breadcrumbs koa-zod-errorhandler/ tsconfig.jsonLatest commit Cannot retrieve latest commit at this time. HistoryHistory File metadata and controls Code Blame 15 lines (15 loc) · 339 Bytes Raw { "compilerOptions": { "target": "es5", "module": "commonjs", "strict": true, "declaration":...