-
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy patherrors.go
More file actions
66 lines (52 loc) · 1.17 KB
/
errors.go
File metadata and controls
66 lines (52 loc) · 1.17 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package ecspresso
import (
"errors"
"github.com/aws/smithy-go"
)
type ErrSkipVerify string
func (e ErrSkipVerify) Error() string {
return string(e)
}
type ErrNotFound string
func (e ErrNotFound) Error() string {
return string(e)
}
type ErrConflictOptions string
func (e ErrConflictOptions) Error() string {
return string(e)
}
type ErrPermissionDenied string
func (e ErrPermissionDenied) Error() string {
return string(e)
}
var (
errNotFound = ErrNotFound("not found")
errSkipVerify = ErrSkipVerify("skip verify")
errPermissionDenied = ErrPermissionDenied("permission denied")
)
func isPermissionError(err error) bool {
// Check if it's wrapped in OperationError
var oe *smithy.OperationError
if errors.As(err, &oe) {
err = oe.Err
}
// Check the actual API error
var ae smithy.APIError
if errors.As(err, &ae) {
switch ae.ErrorCode() {
case "AccessDeniedException", "UnauthorizedException",
"Forbidden", "AccessDenied", "InvalidUserID.NotFound":
return true
}
}
return false
}
func wrapPermissionError(err error) error {
if err == nil {
return nil
}
if isPermissionError(err) {
return ErrPermissionDenied(err.Error())
}
return err
}