/
utilities.go
43 lines (33 loc) · 1.22 KB
/
utilities.go
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
package objazure
import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
"github.com/couchbase/tools-common/cloud/v2/objstore/objerr"
)
// handleError converts an error relating accessing an object via its key into a user friendly error where possible.
func handleError(bucket, key string, err error) error {
if bloberror.HasCode(err, bloberror.AuthenticationFailed) {
return objerr.ErrUnauthenticated
}
if bloberror.HasCode(err, bloberror.AuthorizationFailure) {
return objerr.ErrUnauthorized
}
if bloberror.HasCode(err, bloberror.BlobNotFound) {
// This shouldn't trigger but may aid in debugging in the future
if key == "" {
key = "<empty blob name>"
}
return &objerr.NotFoundError{Type: "blob", Name: key}
}
if bloberror.HasCode(err, bloberror.ContainerNotFound) {
// This shouldn't trigger but may aid in debugging in the future
if bucket == "" {
bucket = "<empty container name>"
}
return &objerr.NotFoundError{Type: "container", Name: bucket}
}
return objerr.HandleError(err)
}
// isKeyNotFound returns a boolean indicating whether the given error is a 'ServiceCodeBlobNotFound' error.
func isKeyNotFound(err error) bool {
return bloberror.HasCode(err, bloberror.BlobNotFound)
}