blob: 0b2d3be62143ec1228660089d171b128fa858f68 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package s3
import (
"strings"
"codeberg.org/gruf/go-storage"
"codeberg.org/gruf/go-storage/internal"
"github.com/minio/minio-go/v7"
)
// CachedErrorResponse can be returned
// when an S3 is configured with caching,
// and the basic details of an error
// response have been stored in the cache.
type CachedErrorResponse struct {
Code string
Key string
}
func (err *CachedErrorResponse) Error() string {
return "cached '" + err.Code + "' response for key:" + err.Key
}
func (err *CachedErrorResponse) Is(other error) bool {
switch other {
case storage.ErrNotFound:
return err.Code == "NoSuchKey"
case storage.ErrAlreadyExists:
return err.Code == "Conflict"
default:
return false
}
}
func isNotFoundError(err error) bool {
errRsp, ok := err.(minio.ErrorResponse)
return ok && errRsp.Code == "NoSuchKey"
}
func isConflictError(err error) bool {
errRsp, ok := err.(minio.ErrorResponse)
return ok && errRsp.Code == "Conflict"
}
func isObjectNameError(err error) bool {
return strings.HasPrefix(err.Error(), "Object name ")
}
func cachedNotFoundError(key string) error {
err := CachedErrorResponse{Code: "NoSuchKey", Key: key}
return internal.WrapErr(&err, storage.ErrNotFound)
}
|