mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -69,6 +69,12 @@ func TestAPIAddEmail(t *testing.T) { | ||||
| 			Primary:  false, | ||||
| 		}, | ||||
| 	}, emails) | ||||
|  | ||||
| 	opts = api.CreateEmailOption{ | ||||
| 		Emails: []string{"notAEmail"}, | ||||
| 	} | ||||
| 	req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts) | ||||
| 	session.MakeRequest(t, req, http.StatusUnprocessableEntity) | ||||
| } | ||||
|  | ||||
| func TestAPIDeleteEmail(t *testing.T) { | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user