@@ -8,7 +8,7 @@ import FlexStyles from '@/styles/flex-styles';
8
8
import InputStyles from '@/styles/input-styles' ;
9
9
import FontStyles from '@/styles/font-styles' ;
10
10
import CommonStyles from '@/styles/common-styles' ;
11
- import { schemaToModel , getTypeInfo , generateExample , removeCircularReferences } from '@/utils/common-utils' ;
11
+ import { schemaToModel , getTypeInfo , generateExample , removeCircularReferences , wait } from '@/utils/common-utils' ;
12
12
import marked from 'marked' ;
13
13
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js' ;
14
14
@@ -407,7 +407,7 @@ export default class ApiRequest extends LitElement {
407
407
:html `< div style ="color:var(--light-fg) "> No Authentication Token provided</ div > ` }
408
408
</ div >
409
409
</ div >
410
- < button class ="m-btn " style ="padding: 6px 0px;width:60px " @click ="${ this . onTryClick } "> TRY</ button >
410
+ < button class ="m-btn try-btn " style ="padding: 6px 0px;width:60px " @click ="${ this . onTryClick } "> TRY</ button >
411
411
</ div >
412
412
${ this . responseMessage === '' ?'' :html `
413
413
< div class ="row " style ="font-size:var(--small-font-size); margin:5px 0 ">
@@ -461,16 +461,16 @@ export default class ApiRequest extends LitElement {
461
461
}
462
462
}
463
463
464
-
465
464
onMimeTypeChange ( e ) {
466
465
let textareaEls = e . target . closest ( '.tab-panel' ) . querySelectorAll ( `textarea.request-body-param` ) ;
467
466
[ ...textareaEls ] . map ( function ( el ) {
468
467
el . style . display = el . classList . contains ( e . target . value ) ?"block" :"none" ;
469
468
} ) ;
470
469
}
471
470
472
- onTryClick ( e ) {
471
+ async onTryClick ( e ) {
473
472
let me = this ;
473
+ let tryBtnEl = e . target ;
474
474
let fetchUrl , fetchOptions , curlUrl , curl = "" , curlHeaders = "" , curlData = "" , curlForm = "" ;
475
475
let requestPanelEl = e . target . closest ( ".request-panel" ) ;
476
476
let pathParamEls = [ ...requestPanelEl . querySelectorAll ( ".request-param[data-ptype='path']" ) ] ;
@@ -632,7 +632,11 @@ export default class ApiRequest extends LitElement {
632
632
me . responseBlobUrl = '' ;
633
633
}
634
634
me . curlSyntax = `${ curl } ${ curlHeaders } ${ curlData } ${ curlForm } ` ;
635
- fetch ( fetchUrl , fetchOptions ) . then ( function ( resp ) {
635
+ try {
636
+ tryBtnEl . disabled = true ;
637
+ await wait ( 1000 ) ;
638
+ const resp = await fetch ( fetchUrl , fetchOptions ) ;
639
+ tryBtnEl . disabled = false ;
636
640
me . responseStatus = resp . ok ? 'success' :'error' ;
637
641
me . responseMessage = `${ resp . statusText } :${ resp . status } ` ;
638
642
me . responseUrl = resp . url ;
@@ -665,10 +669,11 @@ export default class ApiRequest extends LitElement {
665
669
me . responseText = respText ;
666
670
} )
667
671
}
668
- } )
669
- . catch ( function ( err ) {
672
+ }
673
+ catch ( err ) {
674
+ tryBtnEl . disabled = false ;
670
675
me . responseMessage = err . message + " (CORS or Network Issue)" ;
671
- } ) ;
676
+ }
672
677
}
673
678
674
679
downloadResponseBlob ( ) {
0 commit comments