@@ -24,6 +24,9 @@ const (
2424 invalidDomainMsg = "Hostname does not look valid."
2525 invalidVersionMsg = "version cannot be below 0"
2626 invalidKeyMsg = "Key contains invalid base64 chars"
27+ duplicateUserMsg = "A user with that username already exists."
28+ invalidEmailMsg = "Enter a valid email address."
29+ invalidTagMsg = "No nodes matched the provided labels"
2730)
2831
2932var (
3639 ErrMethodNotAllowed = errors .New ("Method Not Allowed" )
3740 // ErrInvalidUsername is returned when the user specifies an invalid or missing username.
3841 ErrInvalidUsername = errors .New (invalidUserMsg )
42+ // ErrDuplicateUsername is returned when trying to register a user that already exists.
43+ ErrDuplicateUsername = errors .New (duplicateUserMsg )
3944 // ErrMissingPassword is returned when a password is not sent with the request.
4045 ErrMissingPassword = errors .New ("A Password is required" )
4146 // ErrLogin is returned when the api cannot login fails with provided username and password
6469 ErrInvalidVersion = errors .New ("The given version is invalid" )
6570 // ErrMissingID is returned when a ID is missing
6671 ErrMissingID = errors .New ("An id is required" )
72+ // ErrInvalidEmail is returned when a user gives an invalid email.
73+ ErrInvalidEmail = errors .New (invalidEmailMsg )
74+ // ErrTagNotFound is returned when no node can be found that matches the tag
75+ ErrTagNotFound = errors .New (invalidTagMsg )
6776)
6877
6978func checkForErrors (res * http.Response ) error {
@@ -88,6 +97,10 @@ func checkForErrors(res *http.Response) error {
8897 return ErrInvalidUsername
8998 }
9099
100+ if scanResponse (bodyMap , "username" , []string {duplicateUserMsg }, true ) {
101+ return ErrDuplicateUsername
102+ }
103+
91104 if scanResponse (bodyMap , "password" , []string {fieldReqMsg }, true ) {
92105 return ErrMissingPassword
93106 }
@@ -128,13 +141,20 @@ func checkForErrors(res *http.Response) error {
128141 return ErrMissingID
129142 }
130143
144+ if scanResponse (bodyMap , "email" , []string {invalidEmailMsg }, true ) {
145+ return ErrInvalidEmail
146+ }
147+
131148 if v , ok := bodyMap ["detail" ].(string ); ok {
132149 if strings .Contains (v , invalidPodMsg ) {
133150 return ErrPodNotFound
134151 }
135152 if strings .Contains (v , invalidVersionMsg ) {
136153 return ErrInvalidVersion
137154 }
155+ if strings .Contains (v , invalidTagMsg ) {
156+ return ErrTagNotFound
157+ }
138158 }
139159
140160 return unknownError (res .StatusCode , bodyMap )
0 commit comments