stub image token refresh

master
Bel LaPointe 2022-01-12 21:54:09 -05:00
parent cf9d6d83c6
commit bfc7aedecf
1 changed files with 19 additions and 2 deletions

View File

@ -12,8 +12,21 @@ import (
"time"
)
var ErrBadAuth = errors.New("auth has failed")
func UploadImage(b []byte) (string, error) {
return uploadImage(b)
path, err := uploadImage(b)
if err == ErrBadAuth {
if err := refreshToken(); err != nil {
return "", err
}
path, err = uploadImage(b)
}
return path, err
}
func refreshToken() error {
return errors.New("not impl")
}
func uploadImage(b []byte) (string, error) {
@ -49,7 +62,11 @@ func uploadImage(b []byte) (string, error) {
}
defer response.Body.Close()
b, _ = ioutil.ReadAll(response.Body)
if response.StatusCode != http.StatusOK {
switch response.StatusCode {
case http.StatusOK:
case 401, 403:
return "", ErrBadAuth
default:
return "", fmt.Errorf("error uploading image: (%d) %s", response.StatusCode, b)
}
var result struct {