(method, requestPath, body, label, options = {})
| 1843 | } |
| 1844 | |
| 1845 | async function retryHttpJson(method, requestPath, body, label, options = {}) { |
| 1846 | const attempts = options.attempts ?? 3; |
| 1847 | const delayMs = options.delayMs ?? 2_000; |
| 1848 | let lastError; |
| 1849 | for (let attempt = 1; attempt <= attempts; attempt += 1) { |
| 1850 | try { |
| 1851 | return await httpJson(method, requestPath, body, { |
| 1852 | maxElapsedMs: options.maxElapsedMs ?? httpActionBudgetMs, |
| 1853 | }); |
| 1854 | } catch (error) { |
| 1855 | lastError = error; |
| 1856 | if (attempt === attempts) { |
| 1857 | break; |
| 1858 | } |
| 1859 | await sleep(delayMs); |
| 1860 | } |
| 1861 | } |
| 1862 | throw new Error( |
| 1863 | `${label} failed after ${attempts} attempts: ${lastError?.message ?? lastError}`, |
| 1864 | ); |
| 1865 | } |
| 1866 | |
| 1867 | function httpBuffer(method, requestPath, body, options = {}) { |
| 1868 | const payload = body === undefined ? null : Buffer.from(JSON.stringify(body)); |
no test coverage detected