• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

semperai / amica-personas / 18257321905

05 Oct 2025 10:11AM UTC coverage: 19.184% (-0.8%) from 20.007%
18257321905

push

github

web-flow
Merge pull request #23 from kasumi-1/import-api

Add new API service with credit-based auth and monitoring

894 of 1155 branches covered (77.4%)

Branch coverage included in aggregate %.

0 of 1185 new or added lines in 15 files covered. (0.0%)

4589 of 27426 relevant lines covered (16.73%)

59.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/api/src/utils/fetchWithRetry.ts
NEW
1
import { env } from "@/utils/envConfig";
×
2

NEW
3
const TRACK_N = 10;
×
NEW
4
const speed = new Map<string, number[]>();
×
5

NEW
6
export async function fetchWithRetry(
×
NEW
7
  urls: string | string[],
×
NEW
8
  options: any,
×
NEW
9
  retries = env.MAX_RETRIES,
×
NEW
10
): Promise<Response> {
×
NEW
11
  let url = "";
×
NEW
12
  if (typeof urls === "string") {
×
NEW
13
    url = urls;
×
NEW
14
  } else {
×
NEW
15
    url = urls[0];
×
NEW
16
  }
×
17

NEW
18
  try {
×
NEW
19
    const start = Date.now();
×
NEW
20
    const response = await fetch(url, options);
×
NEW
21
    const duration = Date.now() - start;
×
22

NEW
23
    if (!speed.has(url)) {
×
NEW
24
      speed.set(url, [duration]);
×
NEW
25
    } else {
×
NEW
26
      speed.get(url)!.push(duration);
×
NEW
27
      if (speed.get(url)!.length > TRACK_N) {
×
NEW
28
        speed.get(url)!.shift();
×
NEW
29
      }
×
NEW
30
    }
×
31

NEW
32
    const averageSpeed = speed.get(url)!.reduce((a, b) => a + b) / speed.get(url)!.length;
×
33

NEW
34
    console.log(`Request to ${url} took ${duration}ms (average: ${averageSpeed}ms)`);
×
NEW
35
    if (!response.ok) {
×
NEW
36
      throw new Error(`HTTP error! status: ${response.status}`);
×
NEW
37
    }
×
NEW
38
    return response;
×
NEW
39
  } catch (error) {
×
NEW
40
    if (retries > 0) {
×
NEW
41
      console.log(`Retrying ${url} attempts left: ${retries - 1}`);
×
NEW
42
      await new Promise((resolve) => setTimeout(resolve, env.RETRY_DELAY));
×
NEW
43
      return fetchWithRetry(url, options, retries - 1);
×
NEW
44
    } else {
×
NEW
45
      throw error;
×
NEW
46
    }
×
NEW
47
  }
×
NEW
48
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc