repository.Create does not return HTTP status code of the operation on failure
Closed this issue · 2 comments
gphotos-uploader-cli
does not respect Google Photos quote limit because google-photos-api-client-go
album Repository.Create does not return anything useful in the error message that would indicate that the limit has been reached.
All it returns is
(*url.Error)(0xc00072cc30)(Post "https://photoslibrary.googleapis.com/v1/albums?alt=json": POST https://photoslibrary.googleapis.com/v1/albums?alt=json giving up after 5 attempt(s))
Informing the user there has been 5 attempts, but the HTTP code there is no where to be found.
To solve this issue in gphotos-uploader-cli
one can attempt to write something ugly like this
album, err := service.Create(ctx, title)
if err != nil {
if urlerr, ok := err.(*url.Error); ok {
if strings.ToUpper(urlerr.Op) == http.MethodPost && urlerr.URL == "https://photoslibrary.googleapis.com/v1/albums?alt=json" {
wrappedErr := urlerr.Unwrap()
if strings.HasPrefix(wrappedErr.Error(), "POST https://photoslibrary.googleapis.com/v1/albums?alt=json giving up after ") {
return "", fmt.Errorf("quota limit reached for %w, check https://console.cloud.google.com/apis/api/photoslibrary.googleapis.com/quotas", err)
}
}
}
return "", err
}
But since it does not know what the original problem was, it could mislead. So essentially there is no way to fix it in gphotos-uploader-cli
It has to be fixed here, in this project.
The issue happens at line 185 push.go gphotos-uploader-cli
But I am pretty sure there are other places in gphotos-uploader-cli where HTTP failure code would be useful. I would think that Google Photos API reliable return HTTP 429 for quota exceed status.
Finally I would suggest returning http.MethodPost
in urlerr.Op in place of Post
since it would be easier to compare it with a standard constant.