@@ -19,6 +19,7 @@ import https from "https";
19
19
import { DaprClientOptions } from "../../../types/DaprClientOptions" ;
20
20
import { Settings } from '../../../utils/Settings.util' ;
21
21
import { THTTPExecuteParams } from "../../../types/http/THTTPExecuteParams.type"
22
+ import { Logger } from "../../../logger/Logger" ;
22
23
23
24
export default class HTTPClient implements IClient {
24
25
private isInitialized : boolean ;
@@ -28,6 +29,7 @@ export default class HTTPClient implements IClient {
28
29
private readonly clientPort : string ;
29
30
private readonly clientUrl : string ;
30
31
private readonly options : DaprClientOptions ;
32
+ private readonly logger : Logger ;
31
33
32
34
private readonly httpAgent ;
33
35
private readonly httpsAgent ;
@@ -37,11 +39,12 @@ export default class HTTPClient implements IClient {
37
39
, port = Settings . getDefaultHttpPort ( )
38
40
, options : DaprClientOptions = {
39
41
isKeepAlive : true
40
- }
42
+ } ,
41
43
) {
42
44
this . clientHost = host ;
43
45
this . clientPort = port ;
44
46
this . options = options ;
47
+ this . logger = new Logger ( "HTTPClient" , "HTTPClient" , this . options . logger ) ;
45
48
this . isInitialized = false ;
46
49
47
50
if ( ! this . clientHost . startsWith ( 'http://' ) && ! this . clientHost . startsWith ( 'https://' ) ) {
@@ -138,7 +141,7 @@ export default class HTTPClient implements IClient {
138
141
params . headers [ "Content-Type" ] = "text/plain" ;
139
142
break ;
140
143
default :
141
- console . log ( `Unknown body type: ${ typeof params ?. body } , defaulting to "text/plain"` ) ;
144
+ this . logger . warn ( `Unknown body type: ${ typeof params ?. body } , defaulting to "text/plain"` ) ;
142
145
params . headers [ "Content-Type" ] = "text/plain" ;
143
146
break ;
144
147
}
@@ -153,7 +156,8 @@ export default class HTTPClient implements IClient {
153
156
await this . start ( ) ;
154
157
}
155
158
156
- // console.log(`${params.method} - ${urlFull} (${params.body})`);
159
+ this . logger . debug ( `Fetching ${ params . method } ${ urlFull } with body: (${ params . body } )` ) ;
160
+
157
161
const res = await fetch ( urlFull , params ) ;
158
162
159
163
// Parse body
@@ -184,7 +188,7 @@ export default class HTTPClient implements IClient {
184
188
}
185
189
// All the others
186
190
else {
187
- console . log ( txtParsed ) ;
191
+ this . logger . debug ( "Execute response text: %s" , txtParsed ) ;
188
192
throw new Error ( JSON . stringify ( {
189
193
error : "UNKNOWN" ,
190
194
error_msg : `An unknown problem occured and we got the status ${ res . status } with response ${ JSON . stringify ( res ) } `
0 commit comments