Compare commits

...

3 Commits

Author SHA1 Message Date
Kevin Yue
c4fa91f6ea refactor: support cancel during retry 2023-09-01 11:35:22 +08:00
Kevin Yue
69502b22a9 refactor: improve the log 2023-09-01 09:50:23 +08:00
Kevin Yue
356946e635 refactor: redact the gateway address 2023-09-01 09:28:44 +08:00
3 changed files with 25 additions and 9 deletions

View File

@ -64,14 +64,19 @@ export const connectPortalAtom = atom(
throw err;
}
if (err instanceof AbnormalPortalConfigError) {
if (!(err instanceof AbnormalPortalConfigError)) {
throw err;
}
logger.info(
`Got abnormal portal config: ${err.message}, retrying...`
);
set(statusAtom, "prelogin");
prelogin = await portalService.prelogin(portal);
continue;
} else {
throw err;
const isProcessing = get(isProcessingAtom);
if (!isProcessing) {
logger.info("Operation cancelled");
break;
}
}
}

View File

@ -1,6 +1,7 @@
import { atom } from "jotai";
import gatewayService from "../services/gatewayService";
import logger from "../utils/logger";
import { redact } from "../utils/redact";
import { isProcessingAtom, statusAtom } from "./status";
import { connectVpnAtom } from "./vpn";
@ -20,7 +21,7 @@ export const loginGatewayAtom = atom(
set(statusAtom, "gateway-login");
let token: string;
try {
logger.info(`Logging in to gateway ${gateway}...`);
logger.info(`Logging in to gateway ${redact(gateway)}...`);
token = await gatewayService.login(gateway, credential);
} catch (err) {
throw new Error("Failed to login to gateway");

View File

@ -80,6 +80,12 @@ export const loginPortalAtom = atom(
throw new AbnormalPortalConfigError("Empty user auth cookie");
}
logger.info(
`Retrieved ${gateways.length} gateways, userAuthCookie: ${redact(
userAuthCookie
)}, prelogonUserAuthCookie: ${redact(prelogonUserAuthCookie)}`
);
// Here, we have got the portal config successfully, refresh the cached portal data
const previousSelectedGateway = get(selectedGatewayAtom)?.name;
const selectedGateway = gateways.find(
@ -106,7 +112,11 @@ export const loginPortalAtom = atom(
preferredGateway: previousSelectedGateway,
});
logger.info(`Found the preferred gateway: ${name} (${redact(address)})`);
logger.info(
`Found the preferred gateway: ${name} (${redact(
address
)}) for region: ${region}`
);
// Log in to the gateway
await set(loginGatewayAtom, address, {