stub image token refresh
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user