@@ -69,7 +69,11 @@ type Client interface {
69
69
GetMinResolvedTSByStoresIDs (context.Context , []uint64 ) (uint64 , map [uint64 ]uint64 , error )
70
70
71
71
/* Client-related methods */
72
- WithRespHandler (func (resp * http.Response ) error ) Client
72
+ // WithRespHandler sets and returns a new client with the given HTTP response handler.
73
+ // This allows the caller to customize how the response is handled, including error handling logic.
74
+ // Additionally, it is important for the caller to handle the content of the response body properly
75
+ // in order to ensure that it can be read and marshaled correctly into `res`.
76
+ WithRespHandler (func (resp * http.Response , res interface {}) error ) Client
73
77
Close ()
74
78
}
75
79
@@ -80,7 +84,7 @@ type client struct {
80
84
tlsConf * tls.Config
81
85
cli * http.Client
82
86
83
- respHandler func (resp * http.Response ) error
87
+ respHandler func (resp * http.Response , res interface {} ) error
84
88
85
89
requestCounter * prometheus.CounterVec
86
90
executionDuration * prometheus.HistogramVec
@@ -161,7 +165,9 @@ func (c *client) Close() {
161
165
162
166
// WithRespHandler sets and returns a new client with the given HTTP response handler.
163
167
// This allows the caller to customize how the response is handled, including error handling logic.
164
- func (c * client ) WithRespHandler (handler func (resp * http.Response ) error ) Client {
168
+ func (c * client ) WithRespHandler (
169
+ handler func (resp * http.Response , res interface {}) error ,
170
+ ) Client {
165
171
newClient := * c
166
172
newClient .respHandler = handler
167
173
return & newClient
@@ -231,7 +237,7 @@ func (c *client) request(
231
237
232
238
// Give away the response handling to the caller if the handler is set.
233
239
if c .respHandler != nil {
234
- return c .respHandler (resp )
240
+ return c .respHandler (resp , res )
235
241
}
236
242
237
243
defer func () {
0 commit comments