changeset 1979:0bc0312105e4

Improved the error message a bit if an invalid country name is passed via JSON api.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 23 Jan 2019 12:26:09 +0100
parents 0a8fa6893181
children c8e2f6838eaf
files pkg/models/common.go
diffstat 1 files changed, 3 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/models/common.go	Wed Jan 23 12:09:23 2019 +0100
+++ b/pkg/models/common.go	Wed Jan 23 12:26:09 2019 +0100
@@ -61,7 +61,6 @@
 		"AT", "BG", "DE", "HU", "HR",
 		"MD", "RO", "RS", "SK", "UA",
 	}
-	errNoValidCountry = errors.New("Not a valid country")
 )
 
 // UnmarshalJSON ensures that the given string forms a valid
@@ -71,14 +70,14 @@
 	if err := json.Unmarshal(data, &s); err != nil {
 		return err
 	}
-	s = strings.ToUpper(s)
+	u := strings.ToUpper(s)
 	for _, v := range validCountries {
-		if v == s {
+		if v == u {
 			*c = Country(v)
 			return nil
 		}
 	}
-	return errNoValidCountry
+	return fmt.Errorf("'%s' is not a valid country", s)
 }
 
 // Value implements the driver.Valuer interface.