@@ -305,7 +305,7 @@ func (c *Client) parseRequest(r *request, opts ...RequestOption) (err error) {
305
305
if queryString != "" {
306
306
fullURL = fmt .Sprintf ("%s?%s" , fullURL , queryString )
307
307
}
308
- c .debug ("full url: %s, body: %s" , fullURL , bodyString )
308
+ c .debug ("full url: %s, body: %s\n " , fullURL , bodyString )
309
309
310
310
r .fullURL = fullURL
311
311
r .header = header
@@ -324,7 +324,7 @@ func (c *Client) callAPI(ctx context.Context, r *request, opts ...RequestOption)
324
324
}
325
325
req = req .WithContext (ctx )
326
326
req .Header = r .header
327
- c .debug ("request: %#v" , req )
327
+ c .debug ("request: %#v\n " , req )
328
328
f := c .do
329
329
if f == nil {
330
330
f = c .HTTPClient .Do
@@ -345,17 +345,20 @@ func (c *Client) callAPI(ctx context.Context, r *request, opts ...RequestOption)
345
345
err = cerr
346
346
}
347
347
}()
348
- c .debug ("response: %#v" , res )
349
- c .debug ("response body: %s" , string (data ))
350
- c .debug ("response status code: %d" , res .StatusCode )
348
+ c .debug ("response: %#v\n " , res )
349
+ c .debug ("response body: %s\n " , string (data ))
350
+ c .debug ("response status code: %d\n " , res .StatusCode )
351
351
352
352
if res .StatusCode >= http .StatusBadRequest {
353
353
apiErr := new (common.APIError )
354
354
e := json .Unmarshal (data , apiErr )
355
355
if e != nil {
356
- c .debug ("failed to unmarshal json: %s" , e )
356
+ c .debug ("failed to unmarshal json: %s\n " , e )
357
357
}
358
- return nil , & http.Header {}, apiErr
358
+ if ! apiErr .IsValid () {
359
+ return nil , & res .Header , fmt .Errorf ("status_code=%v body=%v" , res .StatusCode , string (data ))
360
+ }
361
+ return nil , & res .Header , apiErr
359
362
}
360
363
return data , & res .Header , nil
361
364
}
0 commit comments