rsponse 404 when delete not exist email (#15383)

fix #15357

Signed-off-by: a1012112796 <1012112796@qq.com>
This commit is contained in:
a1012112796 2021-04-10 14:12:38 +08:00 committed by GitHub
parent 9a0858cecf
commit e375cbfd46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 130 additions and 5 deletions

View file

@ -222,6 +222,21 @@ func (err ErrEmailInvalid) Error() string {
return fmt.Sprintf("e-mail invalid [email: %s]", err.Email)
}
// ErrEmailAddressNotExist email address not exist
type ErrEmailAddressNotExist struct {
Email string
}
// IsErrEmailAddressNotExist checks if an error is an ErrEmailAddressNotExist
func IsErrEmailAddressNotExist(err error) bool {
_, ok := err.(ErrEmailAddressNotExist)
return ok
}
func (err ErrEmailAddressNotExist) Error() string {
return fmt.Sprintf("Email address does not exist [email: %s]", err.Email)
}
// ErrOpenIDAlreadyUsed represents a "OpenIDAlreadyUsed" kind of error.
type ErrOpenIDAlreadyUsed struct {
OpenID string

View file

@ -6,7 +6,6 @@
package models
import (
"errors"
"fmt"
"net/mail"
"strings"
@ -18,9 +17,6 @@ import (
"xorm.io/builder"
)
// ErrEmailAddressNotExist email address not exist
var ErrEmailAddressNotExist = errors.New("Email address does not exist")
// EmailAddress is the list of all email addresses of a user. Can contain the
// primary email address, but is not obligatory.
type EmailAddress struct {
@ -243,7 +239,7 @@ func DeleteEmailAddress(email *EmailAddress) (err error) {
if err != nil {
return err
} else if deleted != 1 {
return ErrEmailAddressNotExist
return ErrEmailAddressNotExist{Email: email.Email}
}
return nil
}