1 // Package awserr represents API error interface accessors for the SDK.
4 // An Error wraps lower level errors with code, message and an original error.
5 // The underlying concrete error type may also satisfy other interfaces which
6 // can be to used to obtain more specific information about the error.
8 // Calling Error() or String() will always include the full information about
9 // an error based on its underlying type.
13 // output, err := s3manage.Upload(svc, input, opts)
15 // if awsErr, ok := err.(awserr.Error); ok {
16 // // Get error details
17 // log.Println("Error:", awsErr.Code(), awsErr.Message())
19 // // Prints out full error message, including original error if there was one.
20 // log.Println("Error:", awsErr.Error())
22 // // Get original error
23 // if origErr := awsErr.OrigErr(); origErr != nil {
24 // // operate on original error.
27 // fmt.Println(err.Error())
31 type Error interface {
32 // Satisfy the generic error interface.
35 // Returns the short phrase depicting the classification of the error.
38 // Returns the error details message.
41 // Returns the original error if one was set. Nil is returned if not set.
45 // BatchError is a batch of errors which also wraps lower level errors with
46 // code, message, and original errors. Calling Error() will include all errors
47 // that occurred in the batch.
49 // Deprecated: Replaced with BatchedErrors. Only defined for backwards
51 type BatchError interface {
52 // Satisfy the generic error interface.
55 // Returns the short phrase depicting the classification of the error.
58 // Returns the error details message.
61 // Returns the original error if one was set. Nil is returned if not set.
65 // BatchedErrors is a batch of errors which also wraps lower level errors with
66 // code, message, and original errors. Calling Error() will include all errors
67 // that occurred in the batch.
69 // Replaces BatchError
70 type BatchedErrors interface {
71 // Satisfy the base Error interface.
74 // Returns the original error if one was set. Nil is returned if not set.
78 // New returns an Error object described by the code, message, and origErr.
80 // If origErr satisfies the Error interface it will not be wrapped within a new
81 // Error object and will instead be returned.
82 func New(code, message string, origErr error) Error {
85 errs = append(errs, origErr)
87 return newBaseError(code, message, errs)
90 // NewBatchError returns an BatchedErrors with a collection of errors as an
92 func NewBatchError(code, message string, errs []error) BatchedErrors {
93 return newBaseError(code, message, errs)
96 // A RequestFailure is an interface to extract request failure information from
97 // an Error such as the request ID of the failed request returned by a service.
98 // RequestFailures may not always have a requestID value if the request failed
99 // prior to reaching the service such as a connection error.
103 // output, err := s3manage.Upload(svc, input, opts)
105 // if reqerr, ok := err.(RequestFailure); ok {
106 // log.Println("Request failed", reqerr.Code(), reqerr.Message(), reqerr.RequestID())
108 // log.Println("Error:", err.Error())
112 // Combined with awserr.Error:
114 // output, err := s3manage.Upload(svc, input, opts)
116 // if awsErr, ok := err.(awserr.Error); ok {
117 // // Generic AWS Error with Code, Message, and original error (if any)
118 // fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
120 // if reqErr, ok := err.(awserr.RequestFailure); ok {
121 // // A service error occurred
122 // fmt.Println(reqErr.StatusCode(), reqErr.RequestID())
125 // fmt.Println(err.Error())
129 type RequestFailure interface {
132 // The status code of the HTTP response.
135 // The request ID returned by the service for a request failure. This will
136 // be empty if no request ID is available such as the request failed due
137 // to a connection error.
141 // NewRequestFailure returns a new request error wrapper for the given Error
143 func NewRequestFailure(err Error, statusCode int, reqID string) RequestFailure {
144 return newRequestError(err, statusCode, reqID)