diff options
author | Gusted <williamzijl7@hotmail.com> | 2022-04-20 23:39:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-20 23:39:30 +0200 |
commit | 23d37673bd4e498d66140c44a2e31ab4725c6ae2 (patch) | |
tree | 34b5b3c46c324a8ba56eebf7ef615f8d1c26a5b6 /routers/api/v1/user | |
parent | When dumping trim the standard suffices instead of a random suffix (#19440) (diff) | |
download | forgejo-23d37673bd4e498d66140c44a2e31ab4725c6ae2.tar.xz forgejo-23d37673bd4e498d66140c44a2e31ab4725c6ae2.zip |
Don't panic on `ErrEmailInvalid` (#19441)
- Don't panic on `ErrEmailInvalid`, this was caused due that we were
trying to force `ErrEmailCharIsNotSupported` interface, which panics.
- Resolves #19397
Diffstat (limited to 'routers/api/v1/user')
-rw-r--r-- | routers/api/v1/user/email.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/routers/api/v1/user/email.go b/routers/api/v1/user/email.go index 9060741c59..170ffb7736 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) |