@@ -31,6 +31,33 @@ import (
3131 "os"
3232)
3333
34+ const (
35+ // general errors
36+ ErrNotImplemented = 9
37+ ErrForbidden = 11
38+ ErrDisabled = 36
39+
40+ // HTTP error status codes
41+ ErrHttpForbidden = 403
42+ ErrHttpInternal = 501
43+
44+ // Internal ArangoDB storage errors
45+ ErrArangoReadOnly = 1004
46+
47+ // General ArangoDB storage errors
48+ ErrArangoConflict = 1200
49+ ErrArangoDocumentNotFound = 1202
50+ ErrArangoDataSourceNotFound = 1203
51+ ErrArangoUniqueConstraintViolated = 1210
52+
53+ // ArangoDB cluster errors
54+ ErrClusterLeadershipChallengeOngoing = 1495
55+ ErrClusterNotLeader = 1496
56+
57+ // User management errors
58+ ErrUserDuplicate = 1702
59+ )
60+
3461// ArangoError is a Go error with arangodb specific error information.
3562type ArangoError struct {
3663 HasError bool `json:"error"`
@@ -95,42 +122,46 @@ func IsArangoErrorWithErrorNum(err error, errorNum ...int) bool {
95122
96123// IsInvalidRequest returns true if the given error is an ArangoError with code 400, indicating an invalid request.
97124func IsInvalidRequest (err error ) bool {
98- return IsArangoErrorWithCode (err , 400 )
125+ return IsArangoErrorWithCode (err , http .StatusBadRequest )
126+
99127}
100128
101129// IsUnauthorized returns true if the given error is an ArangoError with code 401, indicating an unauthorized request.
102130func IsUnauthorized (err error ) bool {
103- return IsArangoErrorWithCode (err , 401 )
131+ return IsArangoErrorWithCode (err , http . StatusUnauthorized )
104132}
105133
106134// IsForbidden returns true if the given error is an ArangoError with code 403, indicating a forbidden request.
107135func IsForbidden (err error ) bool {
108- return IsArangoErrorWithCode (err , 403 )
136+ return IsArangoErrorWithCode (err , http . StatusForbidden )
109137}
110138
111139// IsNotFound returns true if the given error is an ArangoError with code 404, indicating a object not found.
112140func IsNotFound (err error ) bool {
113- return IsArangoErrorWithCode (err , 404 ) || IsArangoErrorWithErrorNum (err , 1202 , 1203 )
141+ return IsArangoErrorWithCode (err , http .StatusNotFound ) ||
142+ IsArangoErrorWithErrorNum (err , ErrArangoDocumentNotFound , ErrArangoDataSourceNotFound )
114143}
115144
116145// IsConflict returns true if the given error is an ArangoError with code 409, indicating a conflict.
117146func IsConflict (err error ) bool {
118- return IsArangoErrorWithCode (err , 409 ) || IsArangoErrorWithErrorNum (err , 1702 )
147+ return IsArangoErrorWithCode (err , http . StatusConflict ) || IsArangoErrorWithErrorNum (err , ErrUserDuplicate )
119148}
120149
121150// IsPreconditionFailed returns true if the given error is an ArangoError with code 412, indicating a failed precondition.
122151func IsPreconditionFailed (err error ) bool {
123- return IsArangoErrorWithCode (err , 412 ) || IsArangoErrorWithErrorNum (err , 1200 , 1210 )
152+ return IsArangoErrorWithCode (err , http .StatusPreconditionFailed ) ||
153+ IsArangoErrorWithErrorNum (err , ErrArangoConflict , ErrArangoUniqueConstraintViolated )
124154}
125155
126156// IsNoLeader returns true if the given error is an ArangoError with code 503 error number 1496.
127157func IsNoLeader (err error ) bool {
128- return IsArangoErrorWithCode (err , 503 ) && IsArangoErrorWithErrorNum (err , 1496 )
158+ return IsArangoErrorWithCode (err , http . StatusServiceUnavailable ) && IsArangoErrorWithErrorNum (err , ErrClusterNotLeader )
129159}
130160
131161// IsNoLeaderOrOngoing return true if the given error is an ArangoError with code 503 and error number 1496 or 1495
132162func IsNoLeaderOrOngoing (err error ) bool {
133- return IsArangoErrorWithCode (err , 503 ) && (IsArangoErrorWithErrorNum (err , 1495 ) || IsArangoErrorWithErrorNum (err , 1496 ))
163+ return IsArangoErrorWithCode (err , http .StatusServiceUnavailable ) &&
164+ IsArangoErrorWithErrorNum (err , ErrClusterLeadershipChallengeOngoing , ErrClusterNotLeader )
134165}
135166
136167// InvalidArgumentError is returned when a go function argument is invalid.
0 commit comments