-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathprojector.go
More file actions
45 lines (40 loc) · 944 Bytes
/
projector.go
File metadata and controls
45 lines (40 loc) · 944 Bytes
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
package sql
import (
"context"
"database/sql/driver"
)
type errorAction int
const (
errorRetry errorAction = iota
errorFail
errorIgnore
errorFallthrough
)
// resolveErrorAction determines the way the provided error should be handled by the projector
func resolveErrorAction(
projectionCallback ProjectionErrorCallback,
notification *ProjectionNotification,
err error,
) errorAction {
switch err {
case ErrProjectionPreviouslyLocked:
return errorFail
case context.Canceled, ErrNoProjectionRequired:
return errorIgnore
case driver.ErrBadConn, ErrConnFailedToAcquire, ErrProjectionFailedToLock:
return errorRetry
default:
switch e := err.(type) {
case *ProjectionHandlerError:
switch projectionCallback(e.Cause(), notification) {
case ProjectionRetry:
return errorRetry
case ProjectionIgnoreError:
return errorIgnore
case ProjectionFail:
return errorFail
}
}
}
return errorFallthrough
}