summaryrefslogtreecommitdiff
path: root/vendor/github.com/cenkalti/backoff/v5/error.go
blob: beb2b38a23d70972789f6f5004bdb985e96dfc8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package backoff

import (
	"fmt"
	"time"
)

// PermanentError signals that the operation should not be retried.
type PermanentError struct {
	Err error
}

// Permanent wraps the given err in a *PermanentError.
func Permanent(err error) error {
	if err == nil {
		return nil
	}
	return &PermanentError{
		Err: err,
	}
}

// Error returns a string representation of the Permanent error.
func (e *PermanentError) Error() string {
	return e.Err.Error()
}

// Unwrap returns the wrapped error.
func (e *PermanentError) Unwrap() error {
	return e.Err
}

// RetryAfterError signals that the operation should be retried after the given duration.
type RetryAfterError struct {
	Duration time.Duration
}

// RetryAfter returns a RetryAfter error that specifies how long to wait before retrying.
func RetryAfter(seconds int) error {
	return &RetryAfterError{Duration: time.Duration(seconds) * time.Second}
}

// Error returns a string representation of the RetryAfter error.
func (e *RetryAfterError) Error() string {
	return fmt.Sprintf("retry after %s", e.Duration)
}