Drop error only on purpose or else report back or log (#514)

- Remove Deadcode
- Simplify Code
- Drop error only on purpose
This commit is contained in:
6543
2021-11-23 15:36:52 +01:00
committed by GitHub
parent f454371e56
commit fe31fb1e06
59 changed files with 464 additions and 347 deletions

View File

@@ -104,7 +104,10 @@ func SetPerm() gin.HandlerFunc {
perm.Repo = repo.FullName
perm.UserID = user.ID
perm.Synced = time.Now().Unix()
store_.PermUpsert(perm)
if err := store_.PermUpsert(perm); err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}
}
}
}

View File

@@ -78,7 +78,7 @@ func MustAdmin() gin.HandlerFunc {
case user == nil:
c.String(401, "User not authorized")
c.Abort()
case user.Admin == false:
case !user.Admin:
c.String(403, "User not authorized")
c.Abort()
default:
@@ -95,7 +95,7 @@ func MustRepoAdmin() gin.HandlerFunc {
case user == nil:
c.String(401, "User not authorized")
c.Abort()
case perm.Admin == false:
case !perm.Admin:
c.String(403, "User not authorized")
c.Abort()
default:

View File

@@ -53,8 +53,10 @@ func Refresh(c *gin.Context) {
// attempts to refresh the access token. If the
// token is refreshed, we must also persist to the
// database.
ok, _ = refresher.Refresh(c, user)
if ok {
ok, err := refresher.Refresh(c, user)
if err != nil {
log.Error().Err(err).Msgf("refresh oauth token of user '%s' failed", user.Login)
} else if ok {
err := store.FromContext(c).UpdateUser(user)
if err != nil {
// we only log the error at this time. not sure