mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-22 18:25:47 +08:00
Improve error handling in GenerateIdForNewUser()
This commit is contained in:
parent
85b86e8831
commit
5c103e8cd3
@ -1021,7 +1021,10 @@ func GenerateIdForNewUser(application *Application) (string, error) {
|
||||
|
||||
lastUserId := -1
|
||||
if lastUser != nil {
|
||||
lastUserId = util.ParseInt(lastUser.Id)
|
||||
lastUserId, err = util.ParseIntWithError(lastUser.Id)
|
||||
if err != nil {
|
||||
return util.GenerateId(), nil
|
||||
}
|
||||
}
|
||||
|
||||
res := strconv.Itoa(lastUserId + 1)
|
||||
|
@ -45,6 +45,19 @@ func ParseInt(s string) int {
|
||||
return i
|
||||
}
|
||||
|
||||
func ParseIntWithError(s string) (int, error) {
|
||||
if s == "" {
|
||||
return 0, fmt.Errorf("ParseIntWithError() error, empty string")
|
||||
}
|
||||
|
||||
i, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func ParseFloat(s string) float64 {
|
||||
f, err := strconv.ParseFloat(s, 64)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user