@tasolutions/express-core
Version:
All libs for express
40 lines (37 loc) • 1.23 kB
JavaScript
;
const {httpStatus} = require('./httpStatus')
module.exports = {
/**
* This function format data json
* @param message
* @param data
* @param statusCode
*/
success: function (res, data, message = 'OK', statusCode = httpStatus.OK) {
return res.status(statusCode).json({
statusCode,
success: true,
message,
data
});
},
/**
* This function format data json
* @param message
* @param statusCode
* @param errorCode
* @param data
* @return {{status: number, success: boolean, error_code: string, message: string, data: *}}
*/
error: function (res, message, statusCode = httpStatus.BAD_REQUEST, errorCode = '') {
return res.status(statusCode).json({
statusCode: statusCode || httpStatus.BAD_REQUEST,
success: false,
message: message || 'Something goes wrong, please try again or contact the administrator.',
data: {
errorCode: errorCode || 'BAD_REQUEST',
messageCode: message || 'Something goes wrong, please try again or contact the administrator.'
}
});
}
};