File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -1465,6 +1465,21 @@ export default class ApiRequest extends LitElement {
1465
1465
const startTime = performance . now ( ) ;
1466
1466
fetchResponse = await fetch ( fetchRequest , { signal } ) ;
1467
1467
const endTime = performance . now ( ) ;
1468
+ // Allow to modify response
1469
+ let resolveModifiedResponse ; // Create a promise that will be resolved from the event listener
1470
+ const modifiedResponsePromise = new Promise ( ( resolve ) => {
1471
+ resolveModifiedResponse = resolve ;
1472
+ } ) ;
1473
+ this . dispatchEvent ( new CustomEvent ( 'fetched-try' , {
1474
+ bubbles : true ,
1475
+ composed : true ,
1476
+ detail : {
1477
+ request : fetchRequest ,
1478
+ response : fetchResponse ,
1479
+ resolveModifiedResponse, // pass the resolver function
1480
+ } ,
1481
+ } ) ) ;
1482
+ fetchResponse = await modifiedResponsePromise ; // Wait for the modified response
1468
1483
responseClone = fetchResponse . clone ( ) ; // create a response clone to allow reading response body again (response.json, response.text etc)
1469
1484
tryBtnEl . disabled = false ;
1470
1485
this . responseMessage = html `${ fetchResponse . statusText ? `${ fetchResponse . statusText } :${ fetchResponse . status } ` : fetchResponse . status } < div style ="color:var(--light-fg) "> Took ${ Math . round ( endTime - startTime ) } milliseconds </ div > ` ;
You can’t perform that action at this time.
0 commit comments