123456789101112131415161718192021222324 |
- 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);
- });
- };
- };
|