-
Notifications
You must be signed in to change notification settings - Fork 12
/
errors.go
61 lines (54 loc) · 1.4 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
56
57
58
59
60
61
package eventstore
import (
"fmt"
"github.com/EventStore/EventStore-Client-Go/v3/esdb"
"github.com/pkg/errors"
)
var (
ErrInvalidEventType = InvalidEventTypeError{}
ErrAggregateNotFound = errors.New("aggregate not found")
ErrInvalidCommandType = errors.New("invalid command type")
ErrInvalidRequestType = errors.New("invalid request type")
ErrInvalidAggregate = errors.New("invalid aggregate")
ErrInvalidAggregateID = errors.New("invalid aggregate id")
ErrInvalidEventVersion = errors.New("invalid event version")
)
type InvalidEventTypeError struct {
EventType string
}
func (e InvalidEventTypeError) Error() string {
return fmt.Sprintf("invalid event type: %s", e.EventType)
}
func IsEventStoreErrorCodeResourceNotFound(err error) bool {
esdbErr, ok := esdb.FromError(err)
if ok {
return false
}
errorCode := esdbErr.Code()
if errorCode == esdb.ErrorCodeResourceNotFound {
return true
}
return false
}
func IsEventStoreErrorCodeResourceAlreadyExists(err error) bool {
esdbErr, ok := esdb.FromError(err)
if ok {
return false
}
errorCode := esdbErr.Code()
if errorCode == esdb.ErrorCodeResourceAlreadyExists {
return true
}
return false
}
func IsEventStoreErrorCodeWrongExpectedVersion(err error) bool {
esdbErr, ok := esdb.FromError(err)
if ok {
return false
}
errorCode := esdbErr.Code()
if errorCode == esdb.ErrorCodeWrongExpectedVersion {
return true
}
return false
}