forked from savaki/eventsource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
52 lines (43 loc) · 1.36 KB
/
error.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
package eventsource
import "fmt"
const (
AggregateNil = "AggregateNil"
DuplicateID = "DuplicateID"
DuplicateVersion = "DuplicateVersion"
DuplicateAt = "DuplicateAt"
DuplicateType = "DuplicateType"
InvalidID = "InvalidID"
InvalidAt = "InvalidAt"
InvalidVersion = "InvalidVersion"
InvalidEncoding = "InvalidEncoding"
UnboundEventType = "UnboundEventType"
AggregateNotFound = "AggregateNotFound"
UnhandledEvent = "UnhandledEvent"
)
// Error provides a standardized error interface for eventsource
type Error interface {
error
// Returns the original error if one was set. Nil is returned if not set.
Cause() error
// Returns the short phrase depicting the classification of the error.
Code() string
// Returns the error details message.
Message() string
}
type baseErr struct {
cause error
code string
message string
}
func (b *baseErr) Cause() error { return b.cause }
func (b *baseErr) Code() string { return b.code }
func (b *baseErr) Message() string { return b.message }
func (b *baseErr) Error() string { return fmt.Sprintf("[%v] %v - %v", b.code, b.message, b.cause) }
func (b *baseErr) String() string { return b.Error() }
func NewError(err error, code, format string, args ...interface{}) error {
return &baseErr{
code: code,
message: fmt.Sprintf(format, args...),
cause: err,
}
}