Skip to content

Commit 2ca715a

Browse files
feat(errors): Add support for duplicate app error (#18)
1 parent 3b6502c commit 2ca715a

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

errors.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
duplicateUserMsg = "A user with that username already exists."
2828
invalidEmailMsg = "Enter a valid email address."
2929
invalidTagMsg = "No nodes matched the provided labels"
30+
duplicateIDMsg = "App with this id already exists."
3031
)
3132

3233
var (
@@ -73,6 +74,8 @@ var (
7374
ErrInvalidEmail = errors.New(invalidEmailMsg)
7475
// ErrTagNotFound is returned when no node can be found that matches the tag
7576
ErrTagNotFound = errors.New(invalidTagMsg)
77+
// ErrDuplicateApp is returned when create an app with an ID that already exists
78+
ErrDuplicateApp = errors.New(duplicateIDMsg)
7679
)
7780

7881
func checkForErrors(res *http.Response) error {
@@ -113,6 +116,10 @@ func checkForErrors(res *http.Response) error {
113116
return ErrInvalidAppName
114117
}
115118

119+
if scanResponse(bodyMap, "id", []string{duplicateIDMsg}, true) {
120+
return ErrDuplicateApp
121+
}
122+
116123
if scanResponse(bodyMap, "key", []string{fieldReqMsg}, true) {
117124
return ErrMissingKey
118125
}

errors_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ func TestErrors(t *testing.T) {
103103
},
104104
expected: ErrInvalidAppName,
105105
},
106+
errorTest{
107+
res: &http.Response{
108+
StatusCode: 400,
109+
Body: readCloser(`{"id":["App with this id already exists."]}`),
110+
},
111+
expected: ErrDuplicateApp,
112+
},
106113
errorTest{
107114
res: &http.Response{
108115
StatusCode: 400,

0 commit comments

Comments
 (0)