Skip to content

Commit 6c3ca48

Browse files
committed
Add driver level error classifiers and tests
1 parent b711895 commit 6c3ca48

File tree

5 files changed

+453
-32
lines changed

5 files changed

+453
-32
lines changed

neo4j/error.go

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ type driverError struct {
4040
message string
4141
}
4242

43+
type sessionExpiredError struct {
44+
message string
45+
}
46+
47+
func (failure *databaseError) BoltError() bool {
48+
return true
49+
}
50+
4351
func (failure *databaseError) Classification() string {
4452
return failure.classification
4553
}
@@ -56,6 +64,10 @@ func (failure *databaseError) Error() string {
5664
return fmt.Sprintf("database returned error [%s]: %s", failure.code, failure.message)
5765
}
5866

67+
func (failure *connectorError) BoltError() bool {
68+
return true
69+
}
70+
5971
func (failure *connectorError) State() int {
6072
return failure.state
6173
}
@@ -72,10 +84,26 @@ func (failure *connectorError) Error() string {
7284
return fmt.Sprintf("expected connection to be in READY state, where it is %d [error is %d]", failure.state, failure.code)
7385
}
7486

87+
func (failure *driverError) BoltError() bool {
88+
return true
89+
}
90+
91+
func (failure *driverError) Message() string {
92+
return failure.message
93+
}
94+
7595
func (failure *driverError) Error() string {
7696
return failure.message
7797
}
7898

99+
func (failure *sessionExpiredError) BoltError() bool {
100+
return true
101+
}
102+
103+
func (failure *sessionExpiredError) Error() string {
104+
return failure.message
105+
}
106+
79107
func newDriverError(format string, args ...interface{}) gobolt.GenericError {
80108
return &driverError{message: fmt.Sprintf(format, args...)}
81109
}
@@ -92,20 +120,42 @@ func isRetriableError(err error) bool {
92120
return gobolt.IsServiceUnavailable(err) || gobolt.IsTransientError(err) || gobolt.IsWriteError(err)
93121
}
94122

95-
// IsServiceUnavailable is a utility method to check if the provided error can be classified
96-
// to be in service unavailable category.
97-
func IsServiceUnavailable(err error) bool {
98-
return gobolt.IsServiceUnavailable(err)
123+
// IsSecurityError is a utility method to check if the provided error is related with any
124+
// TLS failure or authentication issues.
125+
func IsSecurityError(err error) bool {
126+
return gobolt.IsSecurityError(err)
127+
}
128+
129+
// IsAuthenticationError is a utility method to check if the provided error is related with any
130+
// authentication issues.
131+
func IsAuthenticationError(err error) bool {
132+
return gobolt.IsAuthenticationError(err)
99133
}
100134

101-
// IsDriverError is a utility method to check if the provided error is generated by the driver
102-
func IsDriverError(err error) bool {
103-
_, ok := err.(*driverError)
104-
return ok
135+
// IsClientError is a utility method to check if the provided error is related with the client
136+
// carrying out an invalid operation.
137+
func IsClientError(err error) bool {
138+
return gobolt.IsClientError(err)
105139
}
106140

107-
// IsTransientError is a utility method to check if the provided error is a DatabaseError with
108-
// TransientError classification
141+
// IsTransientError is a utility method to check if the provided error is related with a temporary
142+
// failure that may be worked around by retrying.
109143
func IsTransientError(err error) bool {
110144
return gobolt.IsTransientError(err)
111145
}
146+
147+
// IsSessionExpired is a utility method to check if the session no longer satisfy the criteria
148+
// under which it was acquired, e.g. a server no longer accepts write requests.
149+
func IsSessionExpired(err error) bool {
150+
if _, ok := err.(*sessionExpiredError); ok {
151+
return true
152+
}
153+
154+
return gobolt.IsSessionExpired(err)
155+
}
156+
157+
// IsServiceUnavailable is a utility method to check if the provided error can be classified
158+
// to be in service unavailable category.
159+
func IsServiceUnavailable(err error) bool {
160+
return gobolt.IsServiceUnavailable(err)
161+
}

0 commit comments

Comments
 (0)