日志:数据库catch
This commit is contained in:
@@ -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';
|
||||
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');
|
||||
const mongooseLeanGetters = require('mongoose-lean-getters');
|
||||
@@ -35,3 +35,26 @@ export default class BaseModel extends TimeStamps {
|
||||
@prop()
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user