feat: catch all errors
This commit is contained in:
13
src/index.ts
13
src/index.ts
@ -59,7 +59,18 @@ if (config.proxy.mode === "reflect4") {
|
||||
logger.info(`Spawning ${config.proxy.count} proxies...`);
|
||||
for (let i = 0; i < config.proxy.count; i++) {
|
||||
logger.debug(`Spawning proxy ${i + 1}...`);
|
||||
tasks.push(reflect4.spawn(context, config.playwright.url));
|
||||
tasks.push((async () => {
|
||||
const spawnId = `${i + 1}`;
|
||||
while (true) {
|
||||
try {
|
||||
await reflect4.spawn(context, config.playwright.url, spawnId);
|
||||
} catch (e) {
|
||||
logger.error(`[${spawnId}] Error while running: ${e}`);
|
||||
}
|
||||
logger.warn(`[${spawnId}] Restarting in 3 seconds...`);
|
||||
await new Promise(resolve => setTimeout(resolve, 3 * 1000));
|
||||
}
|
||||
})());
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
logger.info("All proxies spawned successfully.");
|
||||
|
||||
@ -3,12 +3,17 @@ import logger from "../logger";
|
||||
import * as twitch from "../website/twitch";
|
||||
import * as constants from "../constants";
|
||||
|
||||
async function spawn(context: BrowserContext, targetUrl: string) {
|
||||
const spawnId = btoa(Math.random().toString()).substring(4,10);
|
||||
async function spawn(context: BrowserContext, targetUrl: string, spawnId: string = "unknown") {
|
||||
const server = constants.REFLECT4_SERVERS[Math.floor(Math.random() * constants.REFLECT4_SERVERS.length)];
|
||||
logger.debug(`[${spawnId}] Using reflect4 server: ${server}`);
|
||||
const page = await context.newPage();
|
||||
await page.goto(server);
|
||||
await page.setViewportSize({width: 640, height: 360});
|
||||
try {
|
||||
await page.goto(server);
|
||||
} catch (e) {
|
||||
logger.error(`[${spawnId}] Error while navigating to proxy website: ${e}`);
|
||||
throw e;
|
||||
}
|
||||
let targetInput: Locator | null = null;
|
||||
const allInput = await page.locator("input").all();
|
||||
for (const input of allInput) {
|
||||
@ -20,7 +25,7 @@ async function spawn(context: BrowserContext, targetUrl: string) {
|
||||
}
|
||||
if (!targetInput) {
|
||||
logger.error(`[${spawnId}] Failed to find input field for URL input`);
|
||||
return;
|
||||
throw new Error(`Failed to find input field for URL input`);
|
||||
}
|
||||
await targetInput.fill(targetUrl);
|
||||
await targetInput.press("Enter");
|
||||
|
||||
Reference in New Issue
Block a user