Files
minio/errors.go

28 lines
918 B
Go
Raw Permalink Normal View History

package minio
import (
miniogo "github.com/minio/minio-go/v7"
"code.nochebuena.dev/go/xerrors"
)
// HandleError maps minio-go errors to xerrors types.
// Also available as client.HandleError(err).
func HandleError(err error) error {
if err == nil {
return nil
}
resp := miniogo.ToErrorResponse(err)
switch resp.Code {
case miniogo.NoSuchBucket:
return xerrors.New(xerrors.ErrNotFound, "bucket not found").WithError(err)
case miniogo.NoSuchKey:
return xerrors.New(xerrors.ErrNotFound, "object not found").WithError(err)
case miniogo.AccessDenied, miniogo.InvalidAccessKeyID:
return xerrors.New(xerrors.ErrPermissionDenied, "access denied").WithError(err)
case miniogo.BucketAlreadyExists, miniogo.BucketAlreadyOwnedByYou:
return xerrors.New(xerrors.ErrAlreadyExists, "bucket already exists").WithError(err)
}
return xerrors.New(xerrors.ErrInternal, "unexpected storage error").WithError(err)
}