Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove panic in internet errors to avoid crashing #2

Merged
merged 1 commit into from Jun 7, 2021

Conversation

ebreak
Copy link
Member

@ebreak ebreak commented Jun 7, 2021

After Casdoor backend throws an error, the front end will show beego panic pages (which is HTML text). SDK can not convert those texts into json, so the SDK will panic an error, which can stop the whole program.
This PR is to ignore internet exceptions in such conditions.

@hsluoyz
Copy link
Member

hsluoyz commented Jun 7, 2021

@kininaru return error as 2nd return value, see:

func CasbinJsGetPermissionForUserOld(e IEnforcer, user string) ([]byte, error) {
	policy, err := e.GetImplicitPermissionsForUser(user)
	if err != nil {
		return nil, err
	}
	permission := make(map[string][]string)
	for i := 0; i < len(policy); i++ {
		permission[policy[i][2]] = append(permission[policy[i][2]], policy[i][1])
	}
	b, _ := json.Marshal(permission)
	return b, nil
}

@ebreak
Copy link
Member Author

ebreak commented Jun 7, 2021

@hsluoyz done.

auth/user.go Outdated Show resolved Hide resolved
auth/util.go Outdated Show resolved Hide resolved
auth/util.go Outdated Show resolved Hide resolved
auth/user.go Outdated Show resolved Hide resolved
auth/user.go Outdated Show resolved Hide resolved
auth/user.go Show resolved Hide resolved
auth/util.go Outdated Show resolved Hide resolved
auth/util.go Outdated Show resolved Hide resolved
Signed-off-by: Kininaru <shiftregister233@outlook.com>

add error as 2nd return value

use built in error

return nil

text align
@hsluoyz hsluoyz merged commit f5c8c22 into casdoor:master Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants