HM-57. Исправление бага
This commit is contained in:
@ -1,5 +1,4 @@
|
|||||||
import * as mongoose from 'mongoose';
|
import * as mongoose from 'mongoose';
|
||||||
import * as moment from 'moment';
|
|
||||||
import * as lodash from 'lodash';
|
import * as lodash from 'lodash';
|
||||||
|
|
||||||
import {Injectable, NestInterceptor, ExecutionContext, CallHandler} from '@nestjs/common';
|
import {Injectable, NestInterceptor, ExecutionContext, CallHandler} from '@nestjs/common';
|
||||||
@ -25,15 +24,15 @@ const saveLog = (
|
|||||||
type: string,
|
type: string,
|
||||||
request: any,
|
request: any,
|
||||||
response: any,
|
response: any,
|
||||||
startTime: moment.Moment,
|
startTime: string,
|
||||||
) => {
|
) => {
|
||||||
const endTime = moment();
|
const endTime = new Date().toJSON();
|
||||||
const error = new ErrorModel({
|
const error = new ErrorModel({
|
||||||
type,
|
type,
|
||||||
request: request,
|
request: request,
|
||||||
response: lodash.isEmpty(response) ? 'Server down, look server-logs' : response,
|
response: lodash.isEmpty(response) ? 'Server down, look server-logs' : response,
|
||||||
startTime: startTime.format(),
|
startTime,
|
||||||
endTime: endTime.format(),
|
endTime,
|
||||||
});
|
});
|
||||||
error.save();
|
error.save();
|
||||||
};
|
};
|
||||||
@ -41,7 +40,7 @@ const saveLog = (
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class LoggingInterceptor implements NestInterceptor {
|
export class LoggingInterceptor implements NestInterceptor {
|
||||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
||||||
const start = moment();
|
const start = new Date().toJSON();
|
||||||
const args = context.getArgs()?.[0] ?? {};
|
const args = context.getArgs()?.[0] ?? {};
|
||||||
const {headers, url, method, body} = args;
|
const {headers, url, method, body} = args;
|
||||||
const request = {
|
const request = {
|
||||||
@ -54,7 +53,6 @@ export class LoggingInterceptor implements NestInterceptor {
|
|||||||
saveLog(STATUSES.OK, request, response, start);
|
saveLog(STATUSES.OK, request, response, start);
|
||||||
}),
|
}),
|
||||||
catchError((err: any) => {
|
catchError((err: any) => {
|
||||||
console.log(typeof err)
|
|
||||||
saveLog(STATUSES.BAD, request, err, start);
|
saveLog(STATUSES.BAD, request, err, start);
|
||||||
throw(err);
|
throw(err);
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import * as mongoose from 'mongoose';
|
import * as mongoose from 'mongoose';
|
||||||
import * as moment from 'moment';
|
|
||||||
|
|
||||||
import {Logger as DefaultLogger} from '@nestjs/common';
|
import {Logger as DefaultLogger} from '@nestjs/common';
|
||||||
import {MONGO_URL, LOG_TYPE} from 'src/consts';
|
import {MONGO_URL, LOG_TYPE} from 'src/consts';
|
||||||
@ -24,7 +23,7 @@ const errorSchema = new mongoose.Schema({
|
|||||||
const ErrorModel = mongoose.model(LOG_TYPE.SERVER, errorSchema);
|
const ErrorModel = mongoose.model(LOG_TYPE.SERVER, errorSchema);
|
||||||
|
|
||||||
const saveError = (type: string, message: string, trace = '') => {
|
const saveError = (type: string, message: string, trace = '') => {
|
||||||
const date = moment().format();
|
const date = new Date().toJSON();
|
||||||
const error = new ErrorModel({
|
const error = new ErrorModel({
|
||||||
type, message, trace, date
|
type, message, trace, date
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user