@@ -6,112 +6,44 @@ if (process.env.canary) {
66 axios . defaults . headers . common [ 'X-Canary' ] = 'canary' // for all requests
77}
88
9- function logRequest ( method , url , body , config ) {
10- console . log ( '\n========== REQUEST ==========' ) ;
11- console . log ( `METHOD: ${ method } ` ) ;
12- console . log ( `URL: ${ url } ` ) ;
13- console . log ( 'HEADERS:' , {
14- ...axios . defaults . headers . common ,
15- ...( config ?. headers || { } )
16- } ) ;
17- if ( body ) {
18- const bodyStr = typeof body === 'string' ? body : JSON . stringify ( body , null , 2 ) ;
19- if ( bodyStr . length > 500 ) {
20- console . log ( 'BODY (truncated):' , bodyStr . substring ( 0 , 500 ) + '...' ) ;
21- } else {
22- console . log ( 'BODY:' , bodyStr ) ;
23- }
24- }
25- console . log ( '=============================\n' ) ;
26- }
27-
28- function logResponse ( method , url , res , isError = false ) {
29- console . log ( '\n========== RESPONSE ==========' ) ;
30- console . log ( `METHOD: ${ method } ` ) ;
31- console . log ( `URL: ${ url } ` ) ;
32- console . log ( `STATUS: ${ res ?. status || 'UNDEFINED' } ` ) ;
33- console . log ( `STATUS TEXT: ${ res ?. statusText || 'UNDEFINED' } ` ) ;
34- if ( isError ) {
35- console . log ( 'ERROR: Request failed' ) ;
36- }
37- if ( res ?. headers ) {
38- console . log ( 'RESPONSE HEADERS:' , res . headers ) ;
39- }
40- if ( res ?. data ) {
41- const dataStr = typeof res . data === 'string' ? res . data : JSON . stringify ( res . data , null , 2 ) ;
42- if ( dataStr . length > 1000 ) {
43- console . log ( 'RESPONSE DATA (truncated):' , dataStr . substring ( 0 , 1000 ) + '...' ) ;
44- } else {
45- console . log ( 'RESPONSE DATA:' , dataStr ) ;
46- }
47- } else {
48- console . log ( 'RESPONSE DATA: UNDEFINED/NULL' ) ;
49- }
50- console . log ( '==============================\n' ) ;
51- }
52-
539function get ( url ) {
5410 return axios . get ( url )
55- . then ( res => {
56- if ( res . status >= 400 ) {
57- logRequest ( 'GET' , url ) ;
58- logResponse ( 'GET' , url , res ) ;
59- }
60- return res ;
61- } )
62- . catch ( error => {
63- logRequest ( 'GET' , url ) ;
64- logResponse ( 'GET' , url , error . response , true ) ;
65- return error . response ;
66- } ) ;
11+ . then ( res => {
12+ return res ;
13+ } )
14+ . catch ( error => {
15+ return error . response ;
16+ } ) ;
6717}
6818
6919function post ( url , body , config ) {
7020 return axios . post ( url , body , config )
71- . then ( res => {
72- if ( res . status >= 400 ) {
73- logRequest ( 'POST' , url , body , config ) ;
74- logResponse ( 'POST' , url , res ) ;
75- }
76- return res ;
77- } )
78- . catch ( error => {
79- logRequest ( 'POST' , url , body , config ) ;
80- logResponse ( 'POST' , url , error . response , true ) ;
81- return error . response ;
82- } ) ;
21+ . then ( res => {
22+ return res ;
23+ } )
24+ . catch ( error => {
25+ return error . response ;
26+ } ) ;
8327}
8428
8529function put ( url , body ) {
8630 return axios . put ( url , body )
87- . then ( res => {
88- if ( res . status >= 400 ) {
89- logRequest ( 'PUT' , url , body ) ;
90- logResponse ( 'PUT' , url , res ) ;
91- }
92- return res ;
93- } )
94- . catch ( error => {
95- logRequest ( 'PUT' , url , body ) ;
96- logResponse ( 'PUT' , url , error . response , true ) ;
97- return error . response ;
98- } ) ;
31+ . then ( res => {
32+ return res ;
33+ } )
34+ . catch ( error => {
35+ return error . response ;
36+ } ) ;
9937}
10038
10139function del ( url ) {
10240 return axios . delete ( url )
103- . then ( res => {
104- if ( res . status >= 400 ) {
105- logRequest ( 'DELETE' , url ) ;
106- logResponse ( 'DELETE' , url , res ) ;
107- }
108- return res ;
109- } )
110- . catch ( error => {
111- logRequest ( 'DELETE' , url ) ;
112- logResponse ( 'DELETE' , url , error . response , true ) ;
113- return error . response ;
114- } ) ;
41+ . then ( res => {
42+ return res ;
43+ } )
44+ . catch ( error => {
45+ return error . response ;
46+ } ) ;
11547}
11648
11749function call ( method , url , body ) {
@@ -130,4 +62,4 @@ function call(method, url, body) {
13062
13163}
13264
133- module . exports = { get, post, put, del, call }
65+ module . exports = { get, post, put, del, call}
0 commit comments