Mercurial > gemma
changeset 4059:07d853f9bf47
Return comprehensible error message in case of duplicate user name
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 25 Jul 2019 09:15:53 +0200 |
parents | 6c5c15b2fb64 |
children | 15c9d4064f0f |
files | pkg/common/errors.go pkg/controllers/user.go |
diffstat | 2 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/common/errors.go Thu Jul 25 09:12:53 2019 +0200 +++ b/pkg/common/errors.go Thu Jul 25 09:15:53 2019 +0200 @@ -46,6 +46,7 @@ const ( notNullViolation = "23502" foreignKeyViolation = "23503" + uniqueViolation = "23505" violatesRowLevelSecurity = "42501" noDataFound = "P0002" ) @@ -80,6 +81,17 @@ } } } + case uniqueViolation: + switch err.SchemaName { + case "internal": + switch err.TableName { + case "user_profiles": + switch err.ConstraintName { + case "user_profiles_pkey": + return "A user with that name already exists" + } + } + } case noDataFound: // Most recent line from stacktrace contains name of failed function recent := strings.SplitN(err.Where, "\n", 1)[0]
--- a/pkg/controllers/user.go Thu Jul 25 09:12:53 2019 +0200 +++ b/pkg/controllers/user.go Thu Jul 25 09:15:53 2019 +0200 @@ -27,6 +27,7 @@ "github.com/gorilla/mux" "gemma.intevation.de/gemma/pkg/auth" + "gemma.intevation.de/gemma/pkg/common" "gemma.intevation.de/gemma/pkg/misc" "gemma.intevation.de/gemma/pkg/models" "gemma.intevation.de/gemma/pkg/scheduler" @@ -262,6 +263,7 @@ } if err != nil { + err = common.HandlePGError(err) return }