Errors: add Code and Kind for external system errors (#1080)
This commit is contained in:
1 parent
77497ccd12
commit
d3146992f1
5 files changed
+20
-1
No files matched your search
@@ -75,7 +75,10 @@ const (
|
||||
MaxRetries Code = 1103 // MaxRetries represent that a db Tx hit max retires allowed
|
||||
Exception Code = 1104 // Exception represent that an underlying db exception was raised
|
||||
|
||||
// Migration setup errors are codes 2000-3000
|
||||
// Migration setup errors are codes 2000-2999
|
||||
MigrationIntegrity Code = 2000 // MigrationIntegrity represents an error with the generated migration related code
|
||||
MigrationLock Code = 2001 // MigrationLock represents an error related to locking of the DB
|
||||
|
||||
// External system errors are reserved codes 3000-3999
|
||||
Unavailable Code = 3000 // Unavailable represents that an external system is unavailable
|
||||
)
|
||||
@@ -222,6 +222,11 @@ func TestCode_Both_String_Info(t *testing.T) {
|
||||
c: MigrationLock,
|
||||
want: MigrationLock,
|
||||
},
|
||||
{
|
||||
name: "Unavailable",
|
||||
c: Unavailable,
|
||||
want: Unavailable,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
@@ -172,4 +172,8 @@ var errorCodeInfo = map[Code]Info{
|
||||
Message: "bad db lock",
|
||||
Kind: Integrity,
|
||||
},
|
||||
Unavailable: {
|
||||
Message: "external system unavailable",
|
||||
Kind: External,
|
||||
},
|
||||
}
|
||||
@@ -12,6 +12,7 @@ const (
|
||||
Transaction
|
||||
Encryption
|
||||
Encoding
|
||||
External
|
||||
)
|
||||
|
||||
func (e Kind) String() string {
|
||||
@@ -24,5 +25,6 @@ func (e Kind) String() string {
|
||||
Transaction: "db transaction issue",
|
||||
Encryption: "encryption issue",
|
||||
Encoding: "encoding issue",
|
||||
External: "external system issue",
|
||||
}[e]
|
||||
}
|
||||
@@ -33,6 +33,11 @@ func TestKind_String(t *testing.T) {
|
||||
e: Search,
|
||||
want: "search issue",
|
||||
},
|
||||
{
|
||||
name: "External",
|
||||
e: External,
|
||||
want: "external system issue",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user