5
// SprintError returns a string of the formatted error code.
7
// Both extra and origErr are optional. If they are included their lines
8
// will be added, but if they are not included their lines will be ignored.
9
func SprintError(code, message, extra string, origErr error) string {
10
msg := fmt.Sprintf("%s: %s", code, message)
12
msg = fmt.Sprintf("%s\n\t%s", msg, extra)
15
msg = fmt.Sprintf("%s\ncaused by: %s", msg, origErr.Error())
20
// A baseError wraps the code and message which defines an error. It also
21
// can be used to wrap an original error object.
23
// Should be used as the root for errors satisfying the awserr.Error. Also
24
// for any error which does not fit into a specific error wrapper type.
25
type baseError struct {
26
// Classification of error
29
// Detailed information about error
32
// Optional original error this error is based off of. Allows building
37
// newBaseError returns an error object for the code, message, and err.
39
// code is a short no whitespace phrase depicting the classification of
40
// the error that is being created.
42
// message is the free flow string containing detailed information about the error.
44
// origErr is the error object which will be nested under the new error to be returned.
45
func newBaseError(code, message string, origErr error) *baseError {
53
// Error returns the string representation of the error.
55
// See ErrorWithExtra for formatting.
57
// Satisfies the error interface.
58
func (b baseError) Error() string {
59
return SprintError(b.code, b.message, "", b.origErr)
62
// String returns the string representation of the error.
63
// Alias for Error to satisfy the stringer interface.
64
func (b baseError) String() string {
68
// Code returns the short phrase depicting the classification of the error.
69
func (b baseError) Code() string {
73
// Message returns the error details message.
74
func (b baseError) Message() string {
78
// OrigErr returns the original error if one was set. Nil is returned if no error
80
func (b baseError) OrigErr() error {
84
// So that the Error interface type can be included as an anonymous field
85
// in the requestError struct and not conflict with the error.Error() method.
88
// A requestError wraps a request or service error.
90
// Composed of baseError for code, message, and original error.
91
type requestError struct {
97
// newRequestError returns a wrapped error with additional information for request
98
// status code, and service requestID.
100
// Should be used to wrap all request which involve service requests. Even if
101
// the request failed without a service response, but had an HTTP status code
102
// that may be meaningful.
104
// Also wraps original errors via the baseError.
105
func newRequestError(err Error, statusCode int, requestID string) *requestError {
106
return &requestError{
108
statusCode: statusCode,
109
requestID: requestID,
113
// Error returns the string representation of the error.
114
// Satisfies the error interface.
115
func (r requestError) Error() string {
116
extra := fmt.Sprintf("status code: %d, request id: %s",
117
r.statusCode, r.requestID)
118
return SprintError(r.Code(), r.Message(), extra, r.OrigErr())
121
// String returns the string representation of the error.
122
// Alias for Error to satisfy the stringer interface.
123
func (r requestError) String() string {
127
// StatusCode returns the wrapped status code for the error
128
func (r requestError) StatusCode() int {
132
// RequestID returns the wrapped requestID
133
func (r requestError) RequestID() string {