33 lines
716 B
Go
33 lines
716 B
Go
package s3errors
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
|
)
|
|
|
|
func Wrap(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
var (
|
|
noSuchBucket *types.NoSuchBucket
|
|
noSuchKey *types.NoSuchKey
|
|
notFound *types.NotFound
|
|
)
|
|
if errors.As(err, &noSuchBucket) || errors.As(err, &noSuchKey) || errors.As(err, ¬Found) {
|
|
return fmt.Errorf("resource not found: %w", err)
|
|
}
|
|
return fmt.Errorf("storage operation failed: %w", err)
|
|
}
|
|
|
|
func IsNotFound(err error) bool {
|
|
var (
|
|
noSuchBucket *types.NoSuchBucket
|
|
noSuchKey *types.NoSuchKey
|
|
notFound *types.NotFound
|
|
)
|
|
return errors.As(err, &noSuchBucket) || errors.As(err, &noSuchKey) || errors.As(err, ¬Found)
|
|
}
|