- public sendResponse(response: ProtocolResponse): void {
- const [uuid, payload] = response;
- if (this.responseHandlers.has(uuid) === true) {
- const res = this.responseHandlers.get(uuid) as ServerResponse;
- res.writeHead(this.responseStatusToStatusCode(payload.status), {
- 'Content-Type': 'application/json',
- });
- res.end(JSON.stringify(payload));
- this.responseHandlers.delete(uuid);
- } else {
+ public sendResponse (response: ProtocolResponse): void {
+ const [uuid, payload] = response
+ try {
+ if (this.hasResponseHandler(uuid)) {
+ const res = this.responseHandlers.get(uuid) as ServerResponse
+ res
+ .writeHead(this.responseStatusToStatusCode(payload.status), {
+ 'Content-Type': 'application/json'
+ })
+ .end(JSONStringifyWithMapSupport(payload))
+ } else {
+ logger.error(
+ `${this.logPrefix(moduleName, 'sendResponse')} Response for unknown request id: ${uuid}`
+ )
+ }
+ } catch (error) {