GCS: properly check for googleapi.Error

Fixes #1936

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2025-03-23 11:37:21 +01:00
parent 3f8fc2c323
commit 2e743ff797

View File

@@ -424,8 +424,9 @@ func (*GCSFs) IsNotExist(err error) bool {
if err == storage.ErrObjectNotExist || err == storage.ErrBucketNotExist {
return true
}
if e, ok := err.(*googleapi.Error); ok {
if e.Code == http.StatusNotFound {
var apiErr *googleapi.Error
if errors.As(err, &apiErr) {
if apiErr.Code == http.StatusNotFound {
return true
}
}
@@ -438,8 +439,9 @@ func (*GCSFs) IsPermission(err error) bool {
if err == nil {
return false
}
if e, ok := err.(*googleapi.Error); ok {
if e.Code == http.StatusForbidden || e.Code == http.StatusUnauthorized {
var apiErr *googleapi.Error
if errors.As(err, &apiErr) {
if apiErr.Code == http.StatusForbidden || apiErr.Code == http.StatusUnauthorized {
return true
}
}