61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
// Copyright (C) MongoDB, Inc. 2023-present.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
// not use this file except in compliance with the License. You may obtain
|
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Based on github.com/aws/aws-sdk-go by Amazon.com, Inc. with code from:
|
|
// - github.com/aws/aws-sdk-go/blob/v1.44.225/aws/awserr/error.go
|
|
// See THIRD-PARTY-NOTICES for original license terms
|
|
|
|
// Package awserr represents API error interface accessors for the SDK.
|
|
package awserr
|
|
|
|
// An Error wraps lower level errors with code, message and an original error.
|
|
// The underlying concrete error type may also satisfy other interfaces which
|
|
// can be to used to obtain more specific information about the error.
|
|
type Error interface {
|
|
// Satisfy the generic error interface.
|
|
error
|
|
|
|
// Returns the short phrase depicting the classification of the error.
|
|
Code() string
|
|
|
|
// Returns the error details message.
|
|
Message() string
|
|
|
|
// Returns the original error if one was set. Nil is returned if not set.
|
|
OrigErr() error
|
|
}
|
|
|
|
// BatchedErrors is a batch of errors which also wraps lower level errors with
|
|
// code, message, and original errors. Calling Error() will include all errors
|
|
// that occurred in the batch.
|
|
//
|
|
// Replaces BatchError
|
|
type BatchedErrors interface {
|
|
// Satisfy the base Error interface.
|
|
Error
|
|
|
|
// Returns the original error if one was set. Nil is returned if not set.
|
|
OrigErrs() []error
|
|
}
|
|
|
|
// New returns an Error object described by the code, message, and origErr.
|
|
//
|
|
// If origErr satisfies the Error interface it will not be wrapped within a new
|
|
// Error object and will instead be returned.
|
|
func New(code, message string, origErr error) Error {
|
|
var errs []error
|
|
if origErr != nil {
|
|
errs = append(errs, origErr)
|
|
}
|
|
return newBaseError(code, message, errs)
|
|
}
|
|
|
|
// NewBatchError returns an BatchedErrors with a collection of errors as an
|
|
// array of errors.
|
|
func NewBatchError(code, message string, errs []error) BatchedErrors {
|
|
return newBaseError(code, message, errs)
|
|
}
|