1 // Copyright (C) MongoDB, Inc. 2023-present. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Based on github.com/aws/aws-sdk-go by Amazon.com, Inc. with code from: 8 // - github.com/aws/aws-sdk-go/blob/v1.44.225/aws/awserr/error.go 9 // See THIRD-PARTY-NOTICES for original license terms 10 11 // Package awserr represents API error interface accessors for the SDK. 12 package awserr 13 14 // An Error wraps lower level errors with code, message and an original error. 15 // The underlying concrete error type may also satisfy other interfaces which 16 // can be to used to obtain more specific information about the error. 17 type Error interface { 18 // Satisfy the generic error interface. 19 error 20 21 // Returns the short phrase depicting the classification of the error. 22 Code() string 23 24 // Returns the error details message. 25 Message() string 26 27 // Returns the original error if one was set. Nil is returned if not set. 28 OrigErr() error 29 } 30 31 // BatchedErrors is a batch of errors which also wraps lower level errors with 32 // code, message, and original errors. Calling Error() will include all errors 33 // that occurred in the batch. 34 // 35 // Replaces BatchError 36 type BatchedErrors interface { 37 // Satisfy the base Error interface. 38 Error 39 40 // Returns the original error if one was set. Nil is returned if not set. 41 OrigErrs() []error 42 } 43 44 // New returns an Error object described by the code, message, and origErr. 45 // 46 // If origErr satisfies the Error interface it will not be wrapped within a new 47 // Error object and will instead be returned. 48 func New(code, message string, origErr error) Error { 49 var errs []error 50 if origErr != nil { 51 errs = append(errs, origErr) 52 } 53 return newBaseError(code, message, errs) 54 } 55 56 // NewBatchError returns an BatchedErrors with a collection of errors as an 57 // array of errors. 58 func NewBatchError(code, message string, errs []error) BatchedErrors { 59 return newBaseError(code, message, errs) 60 } 61