From 97e5bfbe5c408ac77dd8690c67612cc2b2017eed Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Wed, 9 Aug 2023 23:23:33 +0300 Subject: [PATCH] resolve all pending rpc requests on gateway disconnect --- frontend/src/gateway.js | 13 +++++++++++++ frontend/src/request.js | 11 +---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/frontend/src/gateway.js b/frontend/src/gateway.js index be0b567..581b65a 100644 --- a/frontend/src/gateway.js +++ b/frontend/src/gateway.js @@ -13,6 +13,16 @@ export const GatewayErrors = { TOO_MANY_SESSIONS: 4008, }; +// this should be in request.js, but putting it here avoids a circular dependency +export const RequestStatus = { + OK: 0, + NETWORK_EXCEPTION: 1, + JSON_EXCEPTION: 2, + FAILURE_STATUS: 3, + RPC_ERROR: 4, + INVARIANT_RPC_RESPONSE_COUNT: 5, +}; + export const GatewayPayloadType = { Hello: 0, Authenticate: 1, // client @@ -148,6 +158,9 @@ export default { clearInterval(this.heartbeatInterval); } + this.waitingSerials.forEach((resolve) => resolve({ status: RequestStatus.NETWORK_EXCEPTION })); + this.waitingSerials.clear(); + if (code === GatewayErrors.BAD_AUTH) { this.dispatch(GatewayEventType.BadAuth, 1); if (this.reconnectTimeout) diff --git a/frontend/src/request.js b/frontend/src/request.js index 165df0e..446c095 100644 --- a/frontend/src/request.js +++ b/frontend/src/request.js @@ -1,4 +1,4 @@ -import gateway from "./gateway"; +import gateway, { RequestStatus } from "./gateway"; import { apiRoute, getItem } from "./storage"; const method = (methodId, requiresAuthentication) => ({methodId, requiresAuthentication}); @@ -43,15 +43,6 @@ export const RPCError = { INTERNAL_ERROR: { code: 7003, message: "Sorry, we couldn't process this request (internal server error)" }, }; -export const RequestStatus = { - OK: 0, - NETWORK_EXCEPTION: 1, - JSON_EXCEPTION: 2, - FAILURE_STATUS: 3, - RPC_ERROR: 4, - INVARIANT_RPC_RESPONSE_COUNT: 5, -}; - export const RequestStatusToMessage = { [RequestStatus.OK]: "", [RequestStatus.NETWORK_EXCEPTION]: "We couldn't reach the server right now",