repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build(deps-dev): apply updates
[e-mobility-charging-stations-simulator.git]
/
ui
/
web
/
src
/
composables
/
UIClient.ts
diff --git
a/ui/web/src/composables/UIClient.ts
b/ui/web/src/composables/UIClient.ts
index c3107d6310401f91b18056e6691e884e04aa2053..387d73d27529bfaf91e25f068bd9612ce53fb33c 100644
(file)
--- a/
ui/web/src/composables/UIClient.ts
+++ b/
ui/web/src/composables/UIClient.ts
@@
-144,25
+144,29
@@
export class UIClient {
command: ProcedureName,
data: RequestPayload,
): Promise<ResponsePayload> {
command: ProcedureName,
data: RequestPayload,
): Promise<ResponsePayload> {
- let uuid: string;
- return await new Promise<ResponsePayload>((resolve, reject) => {
- uuid = crypto.randomUUID();
- const msg = JSON.stringify([uuid, command, data]);
-
+ return new Promise<ResponsePayload>((resolve, reject) => {
if (this.ws.readyState !== WebSocket.OPEN) {
this.openWS();
}
if (this.ws.readyState === WebSocket.OPEN) {
if (this.ws.readyState !== WebSocket.OPEN) {
this.openWS();
}
if (this.ws.readyState === WebSocket.OPEN) {
- setTimeout(() => {
+ const uuid = crypto.randomUUID();
+ const msg = JSON.stringify([uuid, command, data]);
+ const sendTimeout = setTimeout(() => {
this.deleteResponseHandler(uuid);
return reject(new Error(`Send request '${command}' message timeout`));
}, 60 * 1000);
this.deleteResponseHandler(uuid);
return reject(new Error(`Send request '${command}' message timeout`));
}, 60 * 1000);
- this.ws.send(msg);
+ try {
+ this.ws.send(msg);
+ this.setResponseHandler(uuid, command, resolve, reject);
+ } catch (error) {
+ this.deleteResponseHandler(uuid);
+ reject(error);
+ } finally {
+ clearTimeout(sendTimeout);
+ }
} else {
throw new Error(`Send request '${command}' message: connection not opened`);
}
} else {
throw new Error(`Send request '${command}' message: connection not opened`);
}
-
- this.setResponseHandler(uuid, command, resolve, reject);
});
}
});
}
@@
-176,15
+180,18
@@
export class UIClient {
const [uuid, responsePayload] = response;
if (this.responseHandlers.has(uuid) === true) {
const [uuid, responsePayload] = response;
if (this.responseHandlers.has(uuid) === true) {
+ const { procedureName, resolve, reject } = this.getResponseHandler(uuid)!;
switch (responsePayload.status) {
case ResponseStatus.SUCCESS:
switch (responsePayload.status) {
case ResponseStatus.SUCCESS:
-
this.getResponseHandler(uuid)?.
resolve(responsePayload);
+ resolve(responsePayload);
break;
case ResponseStatus.FAILURE:
break;
case ResponseStatus.FAILURE:
-
this.getResponseHandler(uuid)?.
reject(responsePayload);
+ reject(responsePayload);
break;
default:
break;
default:
- console.error(`Response status not supported: ${responsePayload.status}`);
+ console.error(
+ `Response status for procedure '${procedureName}' not supported: '${responsePayload.status}'`,
+ );
}
this.deleteResponseHandler(uuid);
} else {
}
this.deleteResponseHandler(uuid);
} else {