aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/user
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2022-04-20 22:24:07 +0000
committerGitHub <noreply@github.com>2022-04-20 23:24:07 +0100
commit5863f7e0488e23411c99fbcacc5d7b8cc1570611 (patch)
treed8b18af69cf5f96593c625ca5d0e7ffc0d3a19f3 /routers/api/v1/user
parenta785c46ca8d046b06d442845eb7e02bb87c09b80 (diff)
downloadgitea-5863f7e0488e23411c99fbcacc5d7b8cc1570611.tar.gz
gitea-5863f7e0488e23411c99fbcacc5d7b8cc1570611.zip
Don't panic on `ErrEmailInvalid` (#19441) (#19442)
- Backport #19441 - Don't panic on `ErrEmailInvalid`, this was caused due that we were trying to force `ErrEmailCharIsNotSupported` interface, which panics. - Resolves #19397 Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'routers/api/v1/user')
-rw-r--r--routers/api/v1/user/email.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/routers/api/v1/user/email.go b/routers/api/v1/user/email.go
index ed79723c60..7423bfbf2a 100644
--- a/routers/api/v1/user/email.go
+++ b/routers/api/v1/user/email.go
@@ -80,9 +80,16 @@ func AddEmail(ctx *context.APIContext) {
if err := user_model.AddEmailAddresses(emails); err != nil {
if user_model.IsErrEmailAlreadyUsed(err) {
ctx.Error(http.StatusUnprocessableEntity, "", "Email address has been used: "+err.(user_model.ErrEmailAlreadyUsed).Email)
- } else if user_model.IsErrEmailCharIsNotSupported(err) ||
- user_model.IsErrEmailInvalid(err) {
- errMsg := fmt.Sprintf("Email address %s invalid", err.(user_model.ErrEmailInvalid).Email)
+ } else if user_model.IsErrEmailCharIsNotSupported(err) || user_model.IsErrEmailInvalid(err) {
+ email := ""
+ if typedError, ok := err.(user_model.ErrEmailInvalid); ok {
+ email = typedError.Email
+ }
+ if typedError, ok := err.(user_model.ErrEmailCharIsNotSupported); ok {
+ email = typedError.Email
+ }
+
+ errMsg := fmt.Sprintf("Email address %q invalid", email)
ctx.Error(http.StatusUnprocessableEntity, "", errMsg)
} else {
ctx.Error(http.StatusInternalServerError, "AddEmailAddresses", err)