mirror of
https://github.com/Luzifer/go_helpers.git
synced 2024-12-26 14:01:20 +00:00
26 lines
641 B
Go
26 lines
641 B
Go
|
package backoff
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
type (
|
||
|
// ErrCannotRetry wraps the original error and signals the backoff
|
||
|
// should be stopped now as a retry i.e. would be harmful or would
|
||
|
// make no sense
|
||
|
ErrCannotRetry struct{ inner error }
|
||
|
)
|
||
|
|
||
|
// NewErrCannotRetry wraps the given error into an ErrCannotRetry and
|
||
|
// should be used to break from a Retry() function when the retry
|
||
|
// should stop immediately
|
||
|
func NewErrCannotRetry(err error) error {
|
||
|
return ErrCannotRetry{err}
|
||
|
}
|
||
|
|
||
|
func (e ErrCannotRetry) Error() string {
|
||
|
return fmt.Sprintf("retry cancelled by error: %s", e.inner.Error())
|
||
|
}
|
||
|
|
||
|
func (e ErrCannotRetry) Unwrap() error {
|
||
|
return e.inner
|
||
|
}
|