'use strict'; /** * * * @author Mai * @date * @version */ const moment = require('moment'); const messageType = require('../const/message_type'); module.exports = { moment, setMessage(message, type) { let icon = ''; switch (type) { case messageType.SUCCESS: icon = 'check'; break; case messageType.ERROR: icon = 'exclamation-circle'; break; case messageType.INFO: icon = 'info-circle'; break; case messageType.WARNING: icon = 'warning'; break; default: break; } this.session.message = { type, icon, message, }; }, postError(error, msg) { if (error.stack) { this.session.postError = msg; } else { this.session.postError = error.toString(); } }, ajaxErrorBody(error, msg) { if (error.stack) { this.body = {err: 4, msg: msg, data: null}; } else { this.body = {err: 3, msg: error.toString(), data: null}; } }, log(error) { if (error.stack) { this.logger.error(error); } else { this.setMessage(error, messageType.ERROR); this.getLogger('fail').info(JSON.stringify({ error: error, project: this.session.sessionProject, user: this.session.sessionUser, body: this.session.body, })); } }, get hisOssPath() { return this.app.config.hisOssPath; }, get hisOss() { return this.app.hisOss; }, get stashOssPath() { return this.app.config.stashOssPath; }, print(str) { this.getLogger('out').info(str); }, saveTempFile(filename, text) { const filepath = path.join(this.app.config.logger.dir, this.app.config.version, filename); this.helper.saveBufferFile(text, filepath); } };