samjtro / schwab

⚡ fast unofficial schwab traderapi hook
https://pkg.go.dev/github.com/samjtro/schwab
GNU General Public License v2.0
3 stars 0 forks source link

exception handling #51

Open samjtro opened 1 month ago

samjtro commented 1 month ago
  1. @ Handler() - when calling go test, if one hasn't gone through the Initiate() process via an external import, an error is thrown to the testing library unnecessarily. need to handle it so that potential contributors aren't thrown off.
  2. @ Handler() - error codes shouldn't break the program, it should continue to the next call while alerting the user what the error code was, and clearly telling them which request was unsuccessful.
  3. macOS @ Initiate() - not creating ~/.trade correctly for some reason
samjtro commented 3 weeks 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().

samjtro commented 3 weeks 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().

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     }
samjtro commented 3 weeks ago

@ Initiate() - if the process is broken midway thru, remove ~/.trade