mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-03 03:12:50 +02:00
add retry package (#4458)
This commit is contained in:
parent
0d29401192
commit
5ddfc74645
5 changed files with 416 additions and 0 deletions
48
internal/retry/error.go
Normal file
48
internal/retry/error.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package retry
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// TerminalError is an error that should not be retried
|
||||
type TerminalError interface {
|
||||
error
|
||||
IsTerminal()
|
||||
}
|
||||
|
||||
// terminalError is an error that should not be retried
|
||||
type terminalError struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
// Error implements error for terminalError
|
||||
func (e *terminalError) Error() string {
|
||||
return fmt.Sprintf("terminal error: %v", e.Err)
|
||||
}
|
||||
|
||||
// Unwrap implements errors.Unwrap for terminalError
|
||||
func (e *terminalError) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
// Is implements errors.Is for terminalError
|
||||
func (e *terminalError) Is(err error) bool {
|
||||
//nolint:errorlint
|
||||
_, ok := err.(*terminalError)
|
||||
return ok
|
||||
}
|
||||
|
||||
// IsTerminal implements TerminalError for terminalError
|
||||
func (e *terminalError) IsTerminal() {}
|
||||
|
||||
// NewTerminalError creates a new terminal error that cannot be retried
|
||||
func NewTerminalError(err error) error {
|
||||
return &terminalError{Err: err}
|
||||
}
|
||||
|
||||
// IsTerminalError returns true if the error is a terminal error
|
||||
func IsTerminalError(err error) bool {
|
||||
var te TerminalError
|
||||
return errors.As(err, &te)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue