-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
55 lines (40 loc) · 1.89 KB
/
errors.go
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
47
48
49
50
51
52
53
54
55
package clarimq
import (
"errors"
"fmt"
amqp "github.com/rabbitmq/amqp091-go"
)
// ErrNoActiveConnection occurs when there is no active connection while trying to get the failed recovery notification channel.
var ErrNoActiveConnection = errors.New("no active connection to broker")
// ErrPublishFailedChannelClosed occurs when the channel is accessed while being closed.
var ErrPublishFailedChannelClosed = errors.New("channel is closed")
// ErrPublishFailedChannelClosedCached occurs when the channel is accessed while being closed but publishing was cached.
var ErrPublishFailedChannelClosedCached = errors.New("channel is closed: publishing was cached")
// ErrMaxRetriesExceeded occurs when the maximum number of retries exceeds.
var ErrMaxRetriesExceeded = errors.New("max retries exceeded")
// ErrHealthyConnection occurs when a manual recovery is triggered but the connection persists.
var ErrHealthyConnection = errors.New("connection is healthy, no need to recover")
// ErrInvalidConnection occurs when an invalid connection is passed to a publisher or a consumer.
var ErrInvalidConnection = errors.New("invalid connection")
// ErrConsumerAlreadyRunning occurs when the consumer is attempted to be started but already running.
var ErrConsumerAlreadyRunning = errors.New("consumer is running")
// AMQPError is a custom error type that wraps amqp errors.
type AMQPError amqp.Error
func (e *AMQPError) Error() string {
return fmt.Sprintf("Exception (%d) Reason: %q", e.Code, e.Reason)
}
// ErrRecoveryFailed occurs when the recovery failed after a connection loss.
type RecoveryFailedError struct {
Err error
ConnectionName string
}
// Error implements the Error method of the error interface.
func (e *RecoveryFailedError) Error() string {
str := fmt.Sprintf("failed to recover %s:", e.ConnectionName)
if e.Err != nil {
str += e.Err.Error()
} else {
str += "unknown error"
}
return str
}