Add log.handle
This commit is contained in:
parent
15f8bc417e
commit
1ce17cce76
6 changed files with 16 additions and 36 deletions
|
@ -6,6 +6,8 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/martini-contrib/render"
|
||||
|
||||
"github.com/gogits/logs"
|
||||
|
@ -40,8 +42,8 @@ func Critical(format string, v ...interface{}) {
|
|||
logger.Critical(format, v...)
|
||||
}
|
||||
|
||||
func Handle(status int, title, tmpl string, data base.TmplData, r render.Render, err error) {
|
||||
func Handle(status int, title string, data base.TmplData, r render.Render, err error) {
|
||||
data["ErrorMsg"] = err
|
||||
Error("%s: %v", title, err)
|
||||
r.HTML(status, tmpl, data)
|
||||
r.HTML(status, fmt.Sprintf("status/%d", status), data)
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data b
|
|||
return
|
||||
}
|
||||
|
||||
log.Handle(200, "repo.Create", "base/error", data, r, err)
|
||||
log.Handle(200, "repo.Create", data, r, err)
|
||||
}
|
||||
|
||||
func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
||||
|
@ -76,9 +76,7 @@ func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data b
|
|||
}
|
||||
|
||||
if err := models.DeleteRepository(form.UserId, form.RepoId, form.UserName); err != nil {
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("repo.Delete: %v", err)
|
||||
r.HTML(200, "base/error", data)
|
||||
log.Handle(200, "repo.Delete", data, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -95,9 +93,7 @@ func List(req *http.Request, r render.Render, data base.TmplData, session sessio
|
|||
data["Title"] = "Repositories"
|
||||
repos, err := models.GetRepositories(u)
|
||||
if err != nil {
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("repo.List: %v", err)
|
||||
r.HTML(200, "base/error", data)
|
||||
log.Handle(200, "repo.List", data, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,7 @@ func Single(params martini.Params, r render.Render, data base.TmplData) {
|
|||
|
||||
files, err := models.GetReposFiles(params["username"], params["reponame"], "HEAD", "/")
|
||||
if err != nil {
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("repo.List: %v", err)
|
||||
r.HTML(200, "base/error", data)
|
||||
log.Handle(200, "repo.Single", data, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -40,9 +40,7 @@ func Setting(form auth.UpdateProfileForm, r render.Render, data base.TmplData, r
|
|||
user.Avatar = base.EncodeMd5(form.Avatar)
|
||||
user.AvatarEmail = form.Avatar
|
||||
if err := models.UpdateUser(user); err != nil {
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("setting.Setting: %v", err)
|
||||
r.HTML(200, "base/error", data)
|
||||
log.Handle(200, "setting.Setting", data, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -62,9 +60,7 @@ func SettingPassword(form auth.UpdatePasswdForm, r render.Render, data base.Tmpl
|
|||
user := auth.SignedInUser(session)
|
||||
newUser := &models.User{Passwd: form.NewPasswd}
|
||||
if err := newUser.EncodePasswd(); err != nil {
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("setting.UpdatePasswd: %v", err)
|
||||
r.HTML(200, "base/error", data)
|
||||
log.Handle(200, "setting.SettingPassword", data, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -77,9 +73,7 @@ func SettingPassword(form auth.UpdatePasswdForm, r render.Render, data base.Tmpl
|
|||
} else {
|
||||
user.Passwd = newUser.Passwd
|
||||
if err := models.UpdateUser(user); err != nil {
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("setting.UpdatePasswd: %v", err)
|
||||
r.HTML(200, "base/error", data)
|
||||
log.Handle(200, "setting.SettingPassword", data, r, err)
|
||||
return
|
||||
}
|
||||
data["IsSuccess"] = true
|
||||
|
|
|
@ -22,9 +22,7 @@ func Dashboard(r render.Render, data base.TmplData, session sessions.Session) {
|
|||
data["PageIsUserDashboard"] = true
|
||||
repos, err := models.GetRepositories(&models.User{Id: auth.SignedInId(session)})
|
||||
if err != nil {
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("dashboard: %v", err)
|
||||
r.HTML(200, "base/error", data)
|
||||
log.Handle(200, "user.Dashboard", data, r, err)
|
||||
return
|
||||
}
|
||||
data["MyRepos"] = repos
|
||||
|
@ -37,9 +35,7 @@ func Profile(params martini.Params, r render.Render, data base.TmplData, session
|
|||
// TODO: Need to check view self or others.
|
||||
user, err := models.GetUserByName(params["username"])
|
||||
if err != nil {
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("user.Profile: %v", err)
|
||||
r.HTML(200, "base/error", data)
|
||||
log.Handle(200, "user.Profile", data, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -70,9 +66,7 @@ func SignIn(form auth.LogInForm, data base.TmplData, req *http.Request, r render
|
|||
return
|
||||
}
|
||||
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("user.SignIn: %v", err)
|
||||
r.HTML(200, "base/error", data)
|
||||
log.Handle(200, "user.SignIn", data, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -129,9 +123,7 @@ func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r ren
|
|||
data["ErrorMsg"] = "E-mail address has been already used"
|
||||
r.HTML(200, "user/signup", data)
|
||||
default:
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("user.SignUp: %v", data)
|
||||
r.HTML(200, "base/error", nil)
|
||||
log.Handle(200, "user.SignUp", data, r, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -155,9 +147,7 @@ func Delete(data base.TmplData, req *http.Request, session sessions.Session, r r
|
|||
case models.ErrUserOwnRepos.Error():
|
||||
data["ErrorMsg"] = "Your account still have ownership of repository, you have to delete or transfer them first."
|
||||
default:
|
||||
data["ErrorMsg"] = err
|
||||
log.Error("user.Delete: %v", data)
|
||||
r.HTML(200, "base/error", nil)
|
||||
log.Handle(200, "user.Delete", data, r, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue