@@ -19,9 +19,7 @@ import (
1919 slogmulti "github.com/samber/slog-multi"
2020 "go.opentelemetry.io/contrib/bridges/otelslog"
2121 "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
22- "opencsg.com/csghub-server/api/httpbase"
2322 "opencsg.com/csghub-server/common/config"
24- "opencsg.com/csghub-server/common/errorx"
2523)
2624
2725type HttpDoer interface {
@@ -112,7 +110,7 @@ func (c *HttpClient) Get(ctx context.Context, path string, outObj interface{}) e
112110 fullPath := fmt .Sprintf ("%s%s" , c .endpoint , path )
113111 req , err := http .NewRequestWithContext (ctx , http .MethodGet , fullPath , nil )
114112 if err != nil {
115- return fmt .Errorf ("failed to create request: %w" , errorx . ErrInternalServerError )
113+ return fmt .Errorf ("failed to create request: %w" , err )
116114 }
117115 for _ , opt := range c .authOpts {
118116 opt .Set (req )
@@ -125,17 +123,11 @@ func (c *HttpClient) Get(ctx context.Context, path string, outObj interface{}) e
125123 defer resp .Body .Close ()
126124
127125 if resp .StatusCode != http .StatusOK {
128- var errResp httpbase.R
129- jsonErr := json .NewDecoder (resp .Body ).Decode (& errResp )
130- if jsonErr == nil {
131- customErr := errorx .ParseError (errResp .Msg , errorx .ErrRemoteServiceFail , errResp .Context )
132- return customErr
133- }
134126 return fmt .Errorf ("failed to get response, path:%s, status:%d" , path , resp .StatusCode )
135127 }
136128 err = json .NewDecoder (resp .Body ).Decode (outObj )
137129 if err != nil {
138- return fmt .Errorf ("failed to decode resp body in HttpClient.Get, err:%w" , errorx . ErrInternalServerError )
130+ return fmt .Errorf ("failed to decode resp body in HttpClient.Get, err:%w" , err )
139131 }
140132 return nil
141133}
@@ -170,19 +162,13 @@ func (c *HttpClient) Post(ctx context.Context, path string, data interface{}, ou
170162 defer resp .Body .Close ()
171163
172164 if resp .StatusCode != http .StatusOK {
173- var errResp httpbase.R
174- jsonErr := json .NewDecoder (resp .Body ).Decode (& errResp )
175- if jsonErr == nil {
176- customErr := errorx .ParseError (errResp .Msg , errorx .ErrRemoteServiceFail , errResp .Context )
177- return customErr
178- }
179165 return fmt .Errorf ("failed to get response, path:%s, status:%d" , path , resp .StatusCode )
180166 }
181167
182168 if outObj != nil {
183169 err = json .NewDecoder (resp .Body ).Decode (outObj )
184170 if err != nil {
185- return fmt .Errorf ("failed to decode resp body in HttpClient.Post, err:%w" , errorx . ErrInternalServerError )
171+ return fmt .Errorf ("failed to decode resp body in HttpClient.Post, err:%w" , err )
186172 }
187173 }
188174
@@ -192,11 +178,7 @@ func (c *HttpClient) Post(ctx context.Context, path string, data interface{}, ou
192178func (c * HttpClient ) Do (req * http.Request ) (resp * http.Response , err error ) {
193179 ctx := req .Context ()
194180 fullPath := req .URL .String ()
195- traceID , traceParent , _ := trace .GetOrGenTraceIDFromContext (ctx )
196- if traceParent != "" {
197- req .Header .Set (trace .HeaderTraceparent , traceParent )
198- }
199-
181+ traceID := trace .PropagateTrace (ctx , req .Header )
200182 startTime := time .Now ()
201183 retryTime := time .Now ()
202184 err = retry .Do (
0 commit comments