Skip to content

Commit

Permalink
fix(server): server.listen is not awaited so errors can't be handled …
Browse files Browse the repository at this point in the history
…in higher level

server.listen should be awaited such that higher level code can handle occuring errors.
server.listen should be non-blocking anyway
  • Loading branch information
Gerald Baulig committed Nov 8, 2024
1 parent 824621f commit fbe2062
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/microservice/transport/provider/grpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ export class Server {
// credentials = grpc.credentials.createSsl(
// this.config.credentials.ssl.certs);
}
new Promise((resolve, reject) => {
this.server.listen(this.config.addr, credentials).then(resolve).catch(err => {
this.logger.error('Error starting server', { message: err.message, code: err.code, stack: err.stack });
reject(err);
});
await this.server.listen(
this.config.addr,
credentials
).catch(err => {
this.logger.error('Error starting server', { message: err.message, code: err.code, stack: err.stack });
throw err;
});
this.isBound = true;
}
Expand Down
2 changes: 1 addition & 1 deletion test/cfg/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"logger": {
"console": {
"handleExceptions": false,
"level": "info",
"level": "error",
"colorize": true,
"prettyPrint": true
}
Expand Down

0 comments on commit fbe2062

Please sign in to comment.