import {
ProcedureName,
Protocol,
+ ProtocolRequest,
ProtocolResponse,
ProtocolVersion,
RequestPayload,
this.responseHandlers.delete(uuid);
} else {
logger.error(
- `${this.logPrefix()} ${moduleName}.sendResponse: Response received for unknown request: ${response}`
+ `${this.logPrefix()} ${moduleName}.sendResponse: Response for unknown request: ${response}`
);
}
}
}
req.on('error', (error) => {
logger.error(
- `${this.logPrefix(
- moduleName,
- 'requestListener.req.onerror'
- )} Error at incoming request handling:`,
+ `${this.logPrefix(moduleName, 'requestListener.req.onerror')} Error on HTTP request:`,
error
);
});
}
if (req.method === 'POST') {
const bodyBuffer = [];
- let body: RequestPayload;
req
.on('data', (chunk) => {
bodyBuffer.push(chunk);
})
.on('end', () => {
- body = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload;
+ const body = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload;
this.uiServices
.get(version)
.requestHandler(this.buildRequest(uuid, procedureName, body ?? {}))
throw new BaseError(`Unsupported HTTP method: '${req.method}'`);
}
} catch (error) {
+ logger.error(
+ `${this.logPrefix(moduleName, 'requestListener')} Handle HTTP request error:`,
+ error
+ );
this.sendResponse(this.buildResponse(uuid, { status: ResponseStatus.FAILURE }));
}
}
procedureName: ProcedureName,
requestPayload: RequestPayload
): string {
- return JSON.stringify([id, procedureName, requestPayload]);
+ return JSON.stringify([id, procedureName, requestPayload] as ProtocolRequest);
}
private buildResponse(id: string, responsePayload: ResponsePayload): string {
- return JSON.stringify([id, responsePayload]);
+ return JSON.stringify([id, responsePayload] as ProtocolResponse);
}
private responseStatusToStatusCode(status: ResponseStatus): StatusCodes {
config.emobility.protocol
);
this._ws.onmessage = this.responseHandler.bind(this);
+ this._ws.onerror = (error) => {
+ console.error('WebSocket error: ', error);
+ };
}
private setResponseHandler(
this.getResponseHandler(uuid)?.reject(response);
break;
default:
- throw new Error(`Response status not supported: ${response.status}`);
+ console.error(`Response status not supported: ${response.status}`);
}
this.deleteResponseHandler(uuid);
} else {