()
| 12470 | const urlsToTry = [...urls]; |
| 12471 | |
| 12472 | const tryNext = () => { |
| 12473 | if (urlsToTry.length === 0) { |
| 12474 | reject(new Error(`Failed to load resource after trying all sources. Last error: ${lastError}`)); |
| 12475 | return; |
| 12476 | } |
| 12477 | |
| 12478 | const url = urlsToTry.shift(); |
| 12479 | const xhr = new XMLHttpRequest(); |
| 12480 | xhr.open('GET', url); |
| 12481 | xhr.onload = () => { |
| 12482 | if (xhr.status === 200) { |
| 12483 | resolve(xhr.responseText); |
| 12484 | } else { |
| 12485 | lastError = `Status ${xhr.status} from ${url}`; |
| 12486 | console.warn(`Failed to load ${url}, trying next source...`); |
| 12487 | tryNext(); |
| 12488 | } |
| 12489 | }; |
| 12490 | xhr.onerror = () => { |
| 12491 | lastError = `Network error from ${url}`; |
| 12492 | console.warn(`Failed to load ${url}, trying next source...`); |
| 12493 | tryNext(); |
| 12494 | }; |
| 12495 | xhr.send(); |
| 12496 | }; |
| 12497 | |
| 12498 | tryNext(); |
| 12499 | }); |
no test coverage detected