From d3146992f1f5406d3185038711581ea39f34a35b Mon Sep 17 00:00:00 2001 From: Michael Gaffney Date: Wed, 7 Apr 2021 14:50:00 -0400 Subject: [PATCH] Errors: add Code and Kind for external system errors (#1080) --- internal/errors/code.go | 5 ++++- internal/errors/code_test.go | 5 +++++ internal/errors/info.go | 4 ++++ internal/errors/kind.go | 2 ++ internal/errors/kind_test.go | 5 +++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/errors/code.go b/internal/errors/code.go index a6a4917cf7..9fcae80cdd 100644 --- a/internal/errors/code.go +++ b/internal/errors/code.go @@ -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 ) diff --git a/internal/errors/code_test.go b/internal/errors/code_test.go index 67ec7de66e..a58a07dcf2 100644 --- a/internal/errors/code_test.go +++ b/internal/errors/code_test.go @@ -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) { diff --git a/internal/errors/info.go b/internal/errors/info.go index 704d673c33..e3a8d22f0a 100644 --- a/internal/errors/info.go +++ b/internal/errors/info.go @@ -172,4 +172,8 @@ var errorCodeInfo = map[Code]Info{ Message: "bad db lock", Kind: Integrity, }, + Unavailable: { + Message: "external system unavailable", + Kind: External, + }, } diff --git a/internal/errors/kind.go b/internal/errors/kind.go index 092518ab4e..1cb36ff1c2 100644 --- a/internal/errors/kind.go +++ b/internal/errors/kind.go @@ -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] } diff --git a/internal/errors/kind_test.go b/internal/errors/kind_test.go index e646879790..fb9b826e18 100644 --- a/internal/errors/kind_test.go +++ b/internal/errors/kind_test.go @@ -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) {