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

microsoft / botbuilder-js / 6395137128

03 Oct 2023 03:29PM UTC coverage: 84.903% (+0.03%) from 84.869%
6395137128

push

github

web-flow
port: [#4527][#6655] Implementation of Teams batch APIs (#4535)

* add teams batch operations

* update teamsInfo logic

* add unit tests for batch operations

* fix retry logic

* apply code feedback

* Fix lint issue

---------

Co-authored-by: JhontSouth <jhonatan.sandoval@southworks.com>

9955 of 12972 branches covered (0.0%)

Branch coverage included in aggregate %.

84 of 84 new or added lines in 7 files covered. (100.0%)

20256 of 22611 relevant lines covered (89.58%)

7158.45 hits per line

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

80.0
/libraries/botframework-connector/src/teams/retryAction.ts
1
/**
2
 * Copyright (c) Microsoft Corporation. All rights reserved.
3
 * Licensed under the MIT License.
4
 */
5

6
/**
7
 * Retry a given promise with gradually increasing delay when the HTTP status code received is 429(Too Many Requests).
8
 *
9
 * @param promise a function that returns a promise to retry.
10
 * @param maxRetries the maximum number of times to retry.
11
 * @param initialDelay the initial value to delay before retrying (in milliseconds).
12
 * @returns a promise resolving to the result of the promise from the promise generating function, or undefined.
13
 */
14
export async function retryAction<T>(
2✔
15
    promise: (n: number) => Promise<T>,
16
    maxRetries: number,
17
    initialDelay = 500
36✔
18
): Promise<T | undefined> {
19
    let delay = initialDelay,
36✔
20
        n = 1;
36✔
21
    let errStatusCode: number;
22
    const errorsArray = [];
36✔
23

24
    // Take care of negative or zero
25
    maxRetries = Math.max(maxRetries, 1);
36✔
26

27
    do {
36✔
28
        try {
36✔
29
            // Note: return await intentional so we can catch errors
30
            return await promise(n);
36✔
31
        } catch (err: any) {
32
            errorsArray.push(err);
14✔
33
            errStatusCode = err.statusCode;
14✔
34
            if (err.statusCode == 429) {
14!
35
                await new Promise((resolve) => setTimeout(resolve, delay));
×
36
                delay *= n;
×
37
                n++;
×
38
            }
39
        }
40
    } while (n <= maxRetries && errStatusCode === 429);
28✔
41

42
    throw { errors: errorsArray, message: 'Failed to perform the required operation.' };
14✔
43
}
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

© 2025 Coveralls, Inc