From 0f6fc34a7b6f552f1f91200afb204360e3f802d5 Mon Sep 17 00:00:00 2001 From: peron Date: Tue, 11 Apr 2023 18:12:11 +0800 Subject: [PATCH] feat: use random ip by default --- src/api.ts | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/api.ts b/src/api.ts index 7c8aa95..8f84ddc 100644 --- a/src/api.ts +++ b/src/api.ts @@ -18,23 +18,12 @@ export async function createConversation( cookie, }; - let resp: ConversationResponse; - try { - resp = await fetch(API_ENDPOINT, { headers, redirect: "error" }).then( - (res) => res.json(), - ); - if (!resp.result) { - throw new Error("Invalid response"); - } - } catch (err) { - console.error("retry bing create", err); - resp = await fetch(API_ENDPOINT, { - headers: { ...headers, "x-forwarded-for": randomIP() }, - redirect: "error", - }).then((res) => res.json()); - if (!resp) { - throw new Error(`Failed to fetch (${API_ENDPOINT})`); - } + const resp: ConversationResponse = await fetch(API_ENDPOINT, { + headers: { ...headers, "x-forwarded-for": randomIP() }, + redirect: "error", + }).then((res) => res.json()); + if (!resp) { + throw new Error(`Failed to fetch (${API_ENDPOINT})`); } if (resp.result.value !== "Success") {