You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
613 B
JavaScript
26 lines
613 B
JavaScript
'use strict';
|
|
const logger = require('../../utils/logger.util');
|
|
|
|
module.exports = async (ctx, next) => {
|
|
try {
|
|
const data = await next();
|
|
ctx.body = {
|
|
errcode: 0,
|
|
errmsg: '',
|
|
result: ctx.body || data || null,
|
|
};
|
|
if (!ctx.status) {
|
|
ctx.status = 200; // Set status to 200 if not already set
|
|
}
|
|
} catch (err) {
|
|
logger.error('Error handler:', err);
|
|
// ctx.status = 200; // err.status || 500;
|
|
ctx.body = {
|
|
errcode: err.status || 500,
|
|
errmsg: err.message || 'Internal server error',
|
|
statuscode: err.status,
|
|
result: null,
|
|
};
|
|
}
|
|
};
|