resolve all pending rpc requests on gateway disconnect

This commit is contained in:
hippoz 2023-08-09 23:23:33 +03:00
parent fd8aa70ee2
commit 97e5bfbe5c
Signed by: hippoz
GPG key ID: 56C4E02A85F2FBED
2 changed files with 14 additions and 10 deletions

View file

@ -13,6 +13,16 @@ export const GatewayErrors = {
TOO_MANY_SESSIONS: 4008, 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 = { export const GatewayPayloadType = {
Hello: 0, Hello: 0,
Authenticate: 1, // client Authenticate: 1, // client
@ -148,6 +158,9 @@ export default {
clearInterval(this.heartbeatInterval); clearInterval(this.heartbeatInterval);
} }
this.waitingSerials.forEach((resolve) => resolve({ status: RequestStatus.NETWORK_EXCEPTION }));
this.waitingSerials.clear();
if (code === GatewayErrors.BAD_AUTH) { if (code === GatewayErrors.BAD_AUTH) {
this.dispatch(GatewayEventType.BadAuth, 1); this.dispatch(GatewayEventType.BadAuth, 1);
if (this.reconnectTimeout) if (this.reconnectTimeout)

View file

@ -1,4 +1,4 @@
import gateway from "./gateway"; import gateway, { RequestStatus } from "./gateway";
import { apiRoute, getItem } from "./storage"; import { apiRoute, getItem } from "./storage";
const method = (methodId, requiresAuthentication) => ({methodId, requiresAuthentication}); 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)" }, 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 = { export const RequestStatusToMessage = {
[RequestStatus.OK]: "", [RequestStatus.OK]: "",
[RequestStatus.NETWORK_EXCEPTION]: "We couldn't reach the server right now", [RequestStatus.NETWORK_EXCEPTION]: "We couldn't reach the server right now",