日志:数据库catch
This commit is contained in:
+1
-5
@@ -152,11 +152,7 @@ app.configure(ALL_ENVS, 'systimer', function () {
|
|||||||
function errorHandler(err: Error, msg: any, resp: any,
|
function errorHandler(err: Error, msg: any, resp: any,
|
||||||
session: FrontendOrBackendSession, cb: HandlerCallback) {
|
session: FrontendOrBackendSession, cb: HandlerCallback) {
|
||||||
const errCode = genCode(10);
|
const errCode = genCode(10);
|
||||||
errlogger.debug(`${pinus.app.serverId} error handler`);
|
errlogger.error(`${pinus.app.serverId} error handler \n msg[${JSON.stringify(msg)}] \n resp[${JSON.stringify(resp)}] \n sessionId:${JSON.stringify(session.export())} \n error *${errCode}* stack: ${err.stack}`);
|
||||||
errlogger.debug(`msg[${JSON.stringify(msg)}]`);
|
|
||||||
errlogger.debug(`resp[${JSON.stringify(resp)}]`);
|
|
||||||
errlogger.debug(`sessionId:${JSON.stringify(session.export())}`);
|
|
||||||
errlogger.error(`error *${errCode}* stack: ${err.stack}`);
|
|
||||||
|
|
||||||
if (!resp) {
|
if (!resp) {
|
||||||
resp = resResult(STATUS.GLOBAL_ERR, { errCode });
|
resp = resResult(STATUS.GLOBAL_ERR, { errCode });
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { Rank } from '../../../services/rankService';
|
|||||||
import { checkTaskWithRole, } from '../../../services/taskService';
|
import { checkTaskWithRole, } from '../../../services/taskService';
|
||||||
import { pushData, everydayRefresh } from '../../../services/connectorService';
|
import { pushData, everydayRefresh } from '../../../services/connectorService';
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
|
import { WhiteListModel } from '../../../db/WhiteList';
|
||||||
|
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
new HandlerService(app, {});
|
new HandlerService(app, {});
|
||||||
@@ -308,4 +309,9 @@ export class EntryHandler {
|
|||||||
|
|
||||||
return resResult(STATUS.SUCCESS);
|
return resResult(STATUS.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async test(msg: { magicWord: string }, session: FrontendSession) {
|
||||||
|
let rec = await WhiteListModel.checkTel(1, 2, 'xxxxx');
|
||||||
|
return resResult(STATUS.SUCCESS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -84,6 +84,24 @@ module.exports = {
|
|||||||
'type': 'basic'
|
'type': 'basic'
|
||||||
},
|
},
|
||||||
'backups': 5
|
'backups': 5
|
||||||
|
},
|
||||||
|
'app': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '${opts:base}/../logs/app/app.log',
|
||||||
|
'maxLogSize': 1048576,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
},
|
||||||
|
'error': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '${opts:base}/../logs/app/error.log',
|
||||||
|
'maxLogSize': 1048576,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -124,6 +142,18 @@ module.exports = {
|
|||||||
'appenders': ['pinus-rpc'],
|
'appenders': ['pinus-rpc'],
|
||||||
'level': 'debug'
|
'level': 'debug'
|
||||||
},
|
},
|
||||||
|
'pinus': {
|
||||||
|
'appenders': ['console', 'pinus', 'app'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'info': {
|
||||||
|
'appenders': ['console', 'app'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'err': {
|
||||||
|
'appenders': ['console', 'error'],
|
||||||
|
'level': 'debug'
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+24
-1
@@ -1,4 +1,4 @@
|
|||||||
import { prop, pre, modelOptions, plugin } from '@typegoose/typegoose';
|
import { prop, pre, modelOptions, plugin, getModelForClass as getModelForClassPub } from '@typegoose/typegoose';
|
||||||
import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
||||||
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');
|
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');
|
||||||
const mongooseLeanGetters = require('mongoose-lean-getters');
|
const mongooseLeanGetters = require('mongoose-lean-getters');
|
||||||
@@ -35,3 +35,26 @@ export default class BaseModel extends TimeStamps {
|
|||||||
@prop()
|
@prop()
|
||||||
updatedBy: number; // 最近更新人
|
updatedBy: number; // 最近更新人
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function catchError(T) {
|
||||||
|
class T2 extends T {};
|
||||||
|
let names = Object.getOwnPropertyNames(T);
|
||||||
|
for(let name of names) {
|
||||||
|
if(typeof T[name] == 'function') {
|
||||||
|
T2[name] = async (...args: any) => {
|
||||||
|
console.log('*****', args)
|
||||||
|
try {
|
||||||
|
return await T[name].apply(null, args)
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(`class ${T.name}/ function ${name}/ args ${args.join()}/ ${e.stack}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return T2;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getModelForClass(T) {
|
||||||
|
return getModelForClassPub(catchError(T));
|
||||||
|
}
|
||||||
|
|||||||
+10
-3
@@ -1,5 +1,5 @@
|
|||||||
import BaseModel from './BaseModel';
|
import BaseModel, { getModelForClass } from './BaseModel';
|
||||||
import { getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
import { prop, DocumentType } from '@typegoose/typegoose';
|
||||||
import { WHITE_LIST_TYPE } from '../consts';
|
import { WHITE_LIST_TYPE } from '../consts';
|
||||||
|
|
||||||
export default class WhiteList extends BaseModel {
|
export default class WhiteList extends BaseModel {
|
||||||
@@ -16,7 +16,14 @@ export default class WhiteList extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async checkTel(tel: string) {
|
public static async checkTel(tel: string) {
|
||||||
const rec: WhiteListModelType = await WhiteListModel.findOne({ type: WHITE_LIST_TYPE.TEL, str: tel }).lean();
|
const rec: WhiteListModelType = await WhiteListModel.findOneAndUpdate({}, { type: [] as any }).lean();
|
||||||
|
// const rec: WhiteListModelType = await WhiteListModel.findOne({ type: WHITE_LIST_TYPE.TEL, str: tel }).lean();
|
||||||
|
return rec;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async test(a: number, b: number, c: string) {
|
||||||
|
console.log(a, b, c)
|
||||||
|
const rec: WhiteListModelType = await WhiteListModel.findOneAndUpdate({}, { type: [] as any }).lean();
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user