-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: MarcoMandar <malicemandar@gmail.com>
- Loading branch information
1 parent
4dfcf8c
commit 6b8a9c4
Showing
2 changed files
with
66 additions
and
57 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
packages/client-telegram/src/getOrCreateRecommenderInBe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export async function getOrCreateRecommenderInBe( | ||
recommenderId: string, | ||
username: string, | ||
backendToken: string, | ||
backend: string, | ||
retries = 3, | ||
delayMs = 2000 | ||
) { | ||
for (let attempt = 1; attempt <= retries; attempt++) { | ||
try { | ||
const response = await fetch( | ||
`${backend}/api/updaters/getOrCreateRecommender`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${backendToken}`, | ||
}, | ||
body: JSON.stringify({ | ||
recommenderId: recommenderId, | ||
username: username, | ||
}), | ||
} | ||
); | ||
const data = await response.json(); | ||
return data; | ||
} catch (error) { | ||
console.error( | ||
`Attempt ${attempt} failed: Error getting or creating recommender in backend`, | ||
error | ||
); | ||
if (attempt < retries) { | ||
console.log(`Retrying in ${delayMs} ms...`); | ||
await new Promise((resolve) => setTimeout(resolve, delayMs)); | ||
} else { | ||
console.error("All attempts failed."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters