123456789101112131415161718192021222324 |
- /**
- * @description log middleware
- * @type Function
- * @param options
- */
- const { middlewareLog } = require('../utils/logger');
- module.exports = () => {
- const loggerMiddleware = middlewareLog();
- return async(ctx, next) => {
- // 静态文件不处理
- const isApi = /^\/api/.test(ctx.url);
- if (!isApi) {
- await next();
- return;
- };
- return loggerMiddleware(ctx, next)
- .catch(error => {
- const { body, status, message } = error;
- const errorText = `res: ${JSON.stringify({ status, message, body })}`;
- ctx.$log.error(errorText);
- });
- };
- };
|