mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
feat: return most backend API errors to frontend (#1836)
* feat: return most backend API errros to frontend Signed-off-by: yehong <239859435@qq.com> * refactor: reduce int type change Signed-off-by: yehong <239859435@qq.com> * feat: return err backend in token.go Signed-off-by: yehong <239859435@qq.com> --------- Signed-off-by: yehong <239859435@qq.com>
This commit is contained in:
@ -18,21 +18,29 @@ import (
|
||||
"github.com/casdoor/casdoor/xlsx"
|
||||
)
|
||||
|
||||
func getRoleMap(owner string) map[string]*Role {
|
||||
func getRoleMap(owner string) (map[string]*Role, error) {
|
||||
m := map[string]*Role{}
|
||||
|
||||
roles := GetRoles(owner)
|
||||
roles, err := GetRoles(owner)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, role := range roles {
|
||||
m[role.GetId()] = role
|
||||
}
|
||||
|
||||
return m
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func UploadRoles(owner string, fileId string) bool {
|
||||
func UploadRoles(owner string, fileId string) (bool, error) {
|
||||
table := xlsx.ReadXlsxFile(fileId)
|
||||
|
||||
oldUserMap := getRoleMap(owner)
|
||||
oldUserMap, err := getRoleMap(owner)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
newRoles := []*Role{}
|
||||
for index, line := range table {
|
||||
if index == 0 || parseLineItem(&line, 0) == "" {
|
||||
@ -57,7 +65,7 @@ func UploadRoles(owner string, fileId string) bool {
|
||||
}
|
||||
|
||||
if len(newRoles) == 0 {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
return AddRolesInBatch(newRoles)
|
||||
return AddRolesInBatch(newRoles), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user