[core] Fix: Handle unauthorized error for app-access-tokens

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-02-17 00:53:43 +01:00
parent 08185ced3e
commit f883bdd1c1
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -783,6 +783,12 @@ func (c *Client) request(opts clientRequestOpts) error {
} }
defer resp.Body.Close() defer resp.Body.Close()
if opts.AuthType == authTypeAppAccessToken && resp.StatusCode == http.StatusUnauthorized {
// Seems our token was somehow revoked, clear the token and retry which will get a new token
c.appAccessToken = ""
return errors.New("app-access-token is invalid")
}
if opts.OKStatus != 0 && resp.StatusCode != opts.OKStatus { if opts.OKStatus != 0 && resp.StatusCode != opts.OKStatus {
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {