stub image token refresh
parent
cf9d6d83c6
commit
bfc7aedecf
|
|
@ -12,8 +12,21 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrBadAuth = errors.New("auth has failed")
|
||||||
|
|
||||||
func UploadImage(b []byte) (string, error) {
|
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) {
|
func uploadImage(b []byte) (string, error) {
|
||||||
|
|
@ -49,7 +62,11 @@ func uploadImage(b []byte) (string, error) {
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
b, _ = ioutil.ReadAll(response.Body)
|
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)
|
return "", fmt.Errorf("error uploading image: (%d) %s", response.StatusCode, b)
|
||||||
}
|
}
|
||||||
var result struct {
|
var result struct {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue