Errors: add Code and Kind for external system errors (#1080)

pull/1086/head
Michael Gaffney 5 years ago committed by GitHub
parent 77497ccd12
commit d3146992f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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) {

Loading…
Cancel
Save