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:
yehong
2023-05-30 15:49:39 +08:00
committed by GitHub
parent 34151c0095
commit 02e692a300
105 changed files with 3788 additions and 1734 deletions

View File

@ -32,7 +32,12 @@ func AutoSigninFilter(ctx *context.Context) {
accessToken := util.GetMaxLenStr(ctx.Input.Query("accessToken"), ctx.Input.Query("access_token"), parseBearerToken(ctx))
if accessToken != "" {
token := object.GetTokenByAccessToken(accessToken)
token, err := object.GetTokenByAccessToken(accessToken)
if err != nil {
responseError(ctx, err.Error())
return
}
if token == nil {
responseError(ctx, "Access token doesn't exist")
return
@ -44,7 +49,11 @@ func AutoSigninFilter(ctx *context.Context) {
}
userId := util.GetId(token.Organization, token.User)
application, _ := object.GetApplicationByUserId(fmt.Sprintf("app/%s", token.Application))
application, _, err := object.GetApplicationByUserId(fmt.Sprintf("app/%s", token.Application))
if err != nil {
panic(err)
}
setSessionUser(ctx, userId)
setSessionOidc(ctx, token.Scope, application.ClientId)
return

View File

@ -72,7 +72,11 @@ func getUsernameByClientIdSecret(ctx *context.Context) string {
return ""
}
application := object.GetApplicationByClientId(clientId)
application, err := object.GetApplicationByClientId(clientId)
if err != nil {
panic(err)
}
if application == nil || application.ClientSecret != clientSecret {
return ""
}

View File

@ -34,7 +34,12 @@ func CorsFilter(ctx *context.Context) {
originConf := conf.GetConfigString("origin")
if origin != "" && originConf != "" && origin != originConf {
if object.IsOriginAllowed(origin) {
ok, err := object.IsOriginAllowed(origin)
if err != nil {
panic(err)
}
if ok {
ctx.Output.Header(headerAllowOrigin, origin)
ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS, DELETE")
ctx.Output.Header(headerAllowHeaders, "Content-Type, Authorization")

View File

@ -43,7 +43,11 @@ func getUserByClientIdSecret(ctx *context.Context) string {
return ""
}
application := object.GetApplicationByClientId(clientId)
application, err := object.GetApplicationByClientId(clientId)
if err != nil {
panic(err)
}
if application == nil || application.ClientSecret != clientSecret {
return ""
}

View File

@ -30,7 +30,7 @@ import (
var (
oldStaticBaseUrl = "https://cdn.casbin.org"
newStaticBaseUrl = conf.GetConfigString("staticBaseUrl")
enableGzip, _ = conf.GetConfigBool("enableGzip")
enableGzip = conf.GetConfigBool("enableGzip")
)
func StaticFilter(ctx *context.Context) {