/
errors.go
56 lines (47 loc) · 1.49 KB
/
errors.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
44
45
46
47
48
49
50
51
52
53
54
55
56
package datasync
import (
"github.com/YaleSpinup/apierror"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/datasync"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
func ErrCode(msg string, err error) error {
if aerr, ok := errors.Cause(err).(awserr.Error); ok {
switch aerr.Code() {
case
"Forbidden":
return apierror.New(apierror.ErrForbidden, msg, aerr)
case
// Limit Exceeded
"LimitExceeded":
return apierror.New(apierror.ErrLimitExceeded, msg, aerr)
case
// Not found.
"NotFound":
return apierror.New(apierror.ErrNotFound, msg, aerr)
case
// ErrCodeInvalidRequestException for service response error code
// "InvalidRequestException".
//
// This exception is thrown when the client submits a malformed request.
datasync.ErrCodeInvalidRequestException:
return apierror.New(apierror.ErrBadRequest, msg, err)
case
// ErrCodeInternalException for service response error code
// "InternalException".
//
// This exception is thrown when an error occurs in the DataSync service.
datasync.ErrCodeInternalException:
return apierror.New(apierror.ErrInternalError, msg, err)
case
// Service Unavailable
"ServiceUnavailable":
return apierror.New(apierror.ErrServiceUnavailable, msg, aerr)
default:
return apierror.New(apierror.ErrBadRequest, msg, aerr)
}
}
log.Warnf("uncaught error: %s, returning Internal Server Error", err)
return apierror.New(apierror.ErrInternalError, msg, err)
}