Open samjtro opened 1 month ago
@ Handler() - both with refresh token expiration, as well as with token generation on a separate device, error 401 is generated. need to handle by calling Initiate().
@ Handler() - both with refresh token expiration, as well as with token generation on a separate device, error 401 is generated. need to handle by calling Initiate().
Finished in 9e9412c13f5023f1ffd8c85ad58af26308b88460:
266 if errorCode == 401 {
267 agent = Initiate()
268 req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", agent.tokens.Bearer))
269 resp, err = client.Do(req)
270 if err != nil {
271 return "", err
272 }
273 if resp.StatusCode == 401 {
274 log.Fatalf("[ERR] Invalid Agent. Please remove your ~/.trade directory and reinitiate.")
275 }
276 defer resp.Body.Close()
277 bodyBytes, err = io.ReadAll(resp.Body)
278 if err != nil {
279 return "", err
280 }
281 if resp.StatusCode < 200 || resp.StatusCode > 300 {
282 log.Fatalf("Error %d - %s", resp.StatusCode, string(bodyBytes))
283 }
284 return string(bodyBytes), nil
285 }
@ Initiate() - if the process is broken midway thru, remove ~/.trade