@@ -14,36 +14,37 @@ function run(urlStr, body, options) {
14
14
try {
15
15
opts = buildOpts ( body , cliOpts )
16
16
} catch ( e ) {
17
- console . log ( e . message ) ;
17
+ console . error ( e . message ) ;
18
18
return
19
19
}
20
20
21
- try {
22
- // See: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
23
- fetch ( urlStr , opts )
24
- . then ( res => {
25
- const apiUrl = urlStr . replace ( / \/ $ / , '' )
26
- url = new URL ( apiUrl ) ;
27
- cfg = loadConfig ( url , cliOpts . config )
28
- path = buildPath ( url , cliOpts . config )
29
-
30
- console . log ( `Status: ${ res . status } ${ res . statusText } ` )
31
- console . log ( `Request: ${ opts . method } ${ url } ` )
32
- if ( path . path . pathFormat ) console . log ( `Format: ${ path . path . pathFormat } ` )
33
- if ( cfg ?. [ "docs" ] !== undefined ) console . log ( `Docs: ${ cfg ?. [ "docs" ] . join ( ", " ) } ` )
21
+ // See: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
22
+ fetch ( urlStr , opts )
23
+ . then ( res => {
24
+ const apiUrl = urlStr . replace ( / \/ $ / , '' )
25
+ url = new URL ( apiUrl ) ;
26
+ cfg = loadConfig ( url , cliOpts . config )
27
+ path = buildPath ( url , cliOpts . config )
34
28
35
- comment = buildComment ( url , path , opts . method , res )
36
- return res . json ( )
37
- } )
38
- . then ( json => {
29
+ console . log ( `Status: ${ res . status } ${ res . statusText } ` )
30
+ console . log ( `Request: ${ opts . method } ${ url } ` )
31
+ if ( path . path . pathFormat ) console . log ( `Format: ${ path . path . pathFormat } ` )
32
+ if ( cfg ?. [ "docs" ] !== undefined ) console . log ( `Docs: ${ cfg ?. [ "docs" ] . join ( ", " ) } ` )
33
+ comment = buildComment ( url , path , opts . method , res )
34
+ return res . json ( )
35
+ } )
36
+ . then ( json => {
39
37
const struct = jsonToGo ( JSON . stringify ( json ) , path . struct ) ;
40
38
const content = buildContent ( struct . go , path , comment )
41
39
write ( json , path , content )
42
- } )
43
- ;
44
- } catch ( e ) {
45
- console . log ( e . message ) ;
46
- }
40
+ } , ( ) => {
41
+ console . log ( )
42
+ console . log ( "Response Body is empty." )
43
+ }
44
+ )
45
+ . catch ( ( error ) => {
46
+ console . error ( error ) ;
47
+ } ) ;
47
48
}
48
49
49
50
function write ( json , path , content ) {
@@ -79,9 +80,9 @@ function buildOpts(body, cliOpts) {
79
80
} else {
80
81
const bodyObj = loadJsonOrYaml ( body )
81
82
const sortedBodyObj = Object . keys ( bodyObj ) . sort ( ) . reduce ( ( ret , key ) => {
82
- ret [ key ] = bodyObj [ key ] ;
83
- return ret ;
84
- } , { } ) ;
83
+ ret [ key ] = bodyObj [ key ] ;
84
+ return ret ;
85
+ } , { } ) ;
85
86
opts . body = JSON . stringify ( sortedBodyObj )
86
87
}
87
88
}
0 commit comments