(e)
| 1449 | } |
| 1450 | |
| 1451 | async onTryClick(e) { |
| 1452 | const tryBtnEl = e.target; |
| 1453 | const requestPanelEl = tryBtnEl.closest('.request-panel'); |
| 1454 | const fetchUrl = this.buildFetchURL(requestPanelEl); |
| 1455 | const fetchOptions = this.buildFetchBodyOptions(requestPanelEl); |
| 1456 | const reqHeaders = this.buildFetchHeaders(requestPanelEl); |
| 1457 | this.responseUrl = ''; |
| 1458 | this.responseHeaders = []; |
| 1459 | this.curlSyntax = this.generateCURLSyntax(fetchUrl, reqHeaders, fetchOptions, requestPanelEl); |
| 1460 | this.responseStatus = 'success'; |
| 1461 | this.responseIsBlob = false; |
| 1462 | |
| 1463 | this.respContentDisposition = ''; |
| 1464 | if (this.responseBlobUrl) { |
| 1465 | URL.revokeObjectURL(this.responseBlobUrl); |
| 1466 | this.responseBlobUrl = ''; |
| 1467 | } |
| 1468 | if (this.fetchCredentials) { |
| 1469 | fetchOptions.credentials = this.fetchCredentials; |
| 1470 | } |
| 1471 | const controller = new AbortController(); |
| 1472 | const { signal } = controller; |
| 1473 | fetchOptions.headers = reqHeaders; |
| 1474 | const tempRequest = { url: fetchUrl, ...fetchOptions }; |
| 1475 | this.dispatchEvent(new CustomEvent('before-try', { |
| 1476 | bubbles: true, |
| 1477 | composed: true, |
| 1478 | detail: { |
| 1479 | request: tempRequest, |
| 1480 | controller, |
| 1481 | }, |
| 1482 | })); |
| 1483 | const updatedFetchOptions = { |
| 1484 | method: tempRequest.method, |
| 1485 | headers: tempRequest.headers, |
| 1486 | credentials: tempRequest.credentials, |
| 1487 | body: tempRequest.body, |
| 1488 | }; |
| 1489 | const fetchRequest = new Request(tempRequest.url, updatedFetchOptions); |
| 1490 | |
| 1491 | let fetchResponse; |
| 1492 | let responseClone; |
| 1493 | try { |
| 1494 | let respBlob; |
| 1495 | let respJson; |
| 1496 | let respText; |
| 1497 | tryBtnEl.disabled = true; |
| 1498 | this.responseText = '⌛'; |
| 1499 | this.responseMessage = ''; |
| 1500 | this.requestUpdate(); |
| 1501 | const startTime = performance.now(); |
| 1502 | fetchResponse = await fetch(fetchRequest, { signal }); |
| 1503 | const endTime = performance.now(); |
| 1504 | // Allow to modify response |
| 1505 | /* |
| 1506 | let resolveModifiedResponse; // Create a promise that will be resolved from the event listener |
| 1507 | const modifiedResponsePromise = new Promise((resolve) => { |
| 1508 | resolveModifiedResponse = resolve; |
no test coverage detected