Skip to content

Commit

Permalink
fix(common): Fix error on requestContext that disable logs
Browse files Browse the repository at this point in the history
Closes: #764
  • Loading branch information
Romakita committed Feb 21, 2020
1 parent 1da7b3c commit 8be04b7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/mvc/models/RequestContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ export class RequestContext extends Map<any, any> {
}

async emit(eventName: string, ...args: any[]) {
return this.injector && this.injector.emit(eventName, args);
return this.injector && this.injector.emit(eventName, ...args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class LogIncomingRequestMiddleware implements IMiddleware {
});
}
}

request.ctx.logger.flush();
}

Expand Down
21 changes: 10 additions & 11 deletions packages/common/src/server/utils/contextMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ export class ContextMiddleware {
this.reqIdBuilder = reqIdBuilder;
}

static async onClose(err: any, response: any) {
const {req: request} = response;

await request.ctx.emit("$onResponse", request, response);
await request.ctx.destroy();

delete request.ctx;
delete request.log;
}

async use(request: any, response: any, next: any) {
const {level, ignoreUrlPatterns, maxStackSize} = this;

Expand All @@ -45,17 +55,6 @@ export class ContextMiddleware {

next();
}

static async onClose(err: any, response: any) {
const {req: request} = response;
try {
await request.ctx.emit("$onResponse", request, response);
await request.ctx.destroy();
} catch (er) {}

delete request.ctx;
delete request.log;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tasks/gulp/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
.src([
"test/**/*.{js,js.map,d.ts}",
"test/**/*.{js,js.map,d.ts}",
"packages/**/*.{js,js.map,d.ts,d.ts.map}",
"packages/**/src/**/*.{js,js.map,d.ts,d.ts.map}",
"packages/**/node_modules"
], {read: false})
.pipe(clean());
Expand Down

0 comments on commit 8be04b7

Please sign in to comment.