Fix server crash when client passes malformed JSON (#826)

* Fix server crash when client passes malformed JSON

* Take remarks into account

---------

Co-authored-by: Florent FAYOLLE <florent.fayolle@beta.gouv.fr>
This commit is contained in:
Florent
2024-01-23 18:07:39 +01:00
committed by GitHub
parent 1f5cd0a9d5
commit 5533b9b7ee
3 changed files with 44 additions and 11 deletions

View File

@@ -526,11 +526,19 @@ export class Client {
}
}
private async _onMessage(message: string): Promise<void> {
try {
await this._onMessageImpl(message);
} catch (err) {
this._log.warn(null, 'onMessage error received for message "%s": %s', shortDesc(message), err.stack);
}
}
/**
* Processes a request from a client. All requests from a client get a response, at least to
* indicate success or failure.
*/
private async _onMessage(message: string): Promise<void> {
private async _onMessageImpl(message: string): Promise<void> {
const request = JSON.parse(message);
if (request.beat) {
// this is a heart beat, to keep the websocket alive. No need to reply.