unified API error response

tokarchuk/v1.17
Unknwon 9 years ago
parent b1941f1da1
commit aff49b1c9e
  1. 4
      cmd/web.go
  2. 2
      gogs.go
  3. 5
      modules/base/base.go
  4. 2
      modules/middleware/auth.go
  5. 9
      modules/middleware/context.go
  6. 9
      modules/middleware/repo.go
  7. 4
      routers/api/v1/miscellaneous.go
  8. 49
      routers/api/v1/repo.go
  9. 7
      routers/api/v1/repo_file.go
  10. 27
      routers/api/v1/repo_hooks.go
  11. 3
      routers/api/v1/user.go
  12. 5
      routers/api/v1/user_app.go
  13. 2
      templates/.VERSION

@ -226,7 +226,7 @@ func runWeb(ctx *cli.Context) {
m.Group("", func() { m.Group("", func() {
m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo) m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo)
m.Delete("/:owner/:reponame", v1.RemoveRepo) m.Delete("/:username/:reponame", v1.DeleteRepo)
}, middleware.ApiReqToken()) }, middleware.ApiReqToken())
m.Group("/:username/:reponame", func() { m.Group("/:username/:reponame", func() {
@ -239,7 +239,7 @@ func runWeb(ctx *cli.Context) {
}) })
m.Any("/*", func(ctx *middleware.Context) { m.Any("/*", func(ctx *middleware.Context) {
ctx.HandleAPI(404, "Page not found") ctx.Error(404)
}) })
}) })
}, ignSignIn) }, ignSignIn)

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.6.16.1007 Beta" const APP_VER = "0.6.16.1008 Beta"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

@ -8,11 +8,6 @@ const DOC_URL = "https://github.com/gogits/go-gogs-client/wiki"
type ( type (
TplName string TplName string
ApiJsonErr struct {
Message string `json:"message"`
DocUrl string `json:"url"`
}
) )
var GoGetMetas = make(map[string]bool) var GoGetMetas = make(map[string]bool)

@ -95,7 +95,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {
if !ctx.IsSigned { if !ctx.IsSigned {
// Restrict API calls with error message. // Restrict API calls with error message.
if auth.IsAPIPath(ctx.Req.URL.Path) { if auth.IsAPIPath(ctx.Req.URL.Path) {
ctx.HandleAPI(403, "Only signed in user is allowed to call APIs.") ctx.APIError(403, "", "Only signed in user is allowed to call APIs.")
return return
} }

@ -157,15 +157,22 @@ func (ctx *Context) HandleText(status int, title string) {
ctx.RenderData(status, []byte(title)) ctx.RenderData(status, []byte(title))
} }
func (ctx *Context) HandleAPI(status int, obj interface{}) { // APIError logs error with title if status is 500.
func (ctx *Context) APIError(status int, title string, obj interface{}) {
var message string var message string
if err, ok := obj.(error); ok { if err, ok := obj.(error); ok {
message = err.Error() message = err.Error()
} else { } else {
message = obj.(string) message = obj.(string)
} }
if status == 500 {
log.Error(4, "%s: %s", title, message)
}
ctx.JSON(status, map[string]string{ ctx.JSON(status, map[string]string{
"message": message, "message": message,
"url": base.DOC_URL,
}) })
} }

@ -14,7 +14,6 @@ import (
"github.com/mssola/user_agent" "github.com/mssola/user_agent"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
@ -44,7 +43,7 @@ func ApiRepoAssignment() macaron.Handler {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Error(404) ctx.Error(404)
} else { } else {
ctx.JSON(500, &base.ApiJsonErr{"GetUserByName: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetUserByName", err)
} }
return return
} }
@ -57,17 +56,17 @@ func ApiRepoAssignment() macaron.Handler {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
ctx.Error(404) ctx.Error(404)
} else { } else {
ctx.JSON(500, &base.ApiJsonErr{"GetRepositoryByName: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetRepositoryByName", err)
} }
return return
} else if err = repo.GetOwner(); err != nil { } else if err = repo.GetOwner(); err != nil {
ctx.JSON(500, &base.ApiJsonErr{"GetOwner: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetOwner", err)
return return
} }
mode, err := models.AccessLevel(ctx.User, repo) mode, err := models.AccessLevel(ctx.User, repo)
if err != nil { if err != nil {
ctx.JSON(500, &base.ApiJsonErr{"AccessLevel: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "AccessLevel", err)
return return
} }

@ -16,7 +16,7 @@ import (
// Render an arbitrary Markdown document. // Render an arbitrary Markdown document.
func Markdown(ctx *middleware.Context, form apiv1.MarkdownForm) { func Markdown(ctx *middleware.Context, form apiv1.MarkdownForm) {
if ctx.HasApiError() { if ctx.HasApiError() {
ctx.JSON(422, base.ApiJsonErr{ctx.GetErrMsg(), base.DOC_URL}) ctx.APIError(422, "", ctx.GetErrMsg())
return return
} }
@ -38,7 +38,7 @@ func Markdown(ctx *middleware.Context, form apiv1.MarkdownForm) {
func MarkdownRaw(ctx *middleware.Context) { func MarkdownRaw(ctx *middleware.Context) {
body, err := ctx.Req.Body().Bytes() body, err := ctx.Req.Body().Bytes()
if err != nil { if err != nil {
ctx.JSON(422, base.ApiJsonErr{err.Error(), base.DOC_URL}) ctx.APIError(422, "", err)
return return
} }
ctx.Write(base.RenderRawMarkdown(body, "")) ctx.Write(base.RenderRawMarkdown(body, ""))

@ -15,7 +15,6 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
@ -104,14 +103,14 @@ func SearchRepos(ctx *middleware.Context) {
func ListMyRepos(ctx *middleware.Context) { func ListMyRepos(ctx *middleware.Context) {
ownRepos, err := models.GetRepositories(ctx.User.Id, true) ownRepos, err := models.GetRepositories(ctx.User.Id, true)
if err != nil { if err != nil {
ctx.JSON(500, &base.ApiJsonErr{"GetRepositories: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetRepositories", err)
return return
} }
numOwnRepos := len(ownRepos) numOwnRepos := len(ownRepos)
accessibleRepos, err := ctx.User.GetAccessibleRepositories() accessibleRepos, err := ctx.User.GetAccessibleRepositories()
if err != nil { if err != nil {
ctx.JSON(500, &base.ApiJsonErr{"GetAccessibleRepositories: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetAccessibleRepositories", err)
return return
} }
@ -147,15 +146,14 @@ func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoO
if models.IsErrRepoAlreadyExist(err) || if models.IsErrRepoAlreadyExist(err) ||
models.IsErrNameReserved(err) || models.IsErrNameReserved(err) ||
models.IsErrNamePatternNotAllowed(err) { models.IsErrNamePatternNotAllowed(err) {
ctx.JSON(422, &base.ApiJsonErr{err.Error(), base.DOC_URL}) ctx.APIError(422, "", err)
} else { } else {
log.Error(4, "CreateRepository: %v", err)
if repo != nil { if repo != nil {
if err = models.DeleteRepository(ctx.User.Id, repo.ID); err != nil { if err = models.DeleteRepository(ctx.User.Id, repo.ID); err != nil {
log.Error(4, "DeleteRepository: %v", err) log.Error(4, "DeleteRepository: %v", err)
} }
} }
ctx.Error(500) ctx.APIError(500, "CreateRepository", err)
} }
return return
} }
@ -167,7 +165,7 @@ func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoO
func CreateRepo(ctx *middleware.Context, opt api.CreateRepoOption) { func CreateRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
// Shouldn't reach this condition, but just in case. // Shouldn't reach this condition, but just in case.
if ctx.User.IsOrganization() { if ctx.User.IsOrganization() {
ctx.JSON(422, "not allowed creating repository for organization") ctx.APIError(422, "", "not allowed creating repository for organization")
return return
} }
createRepo(ctx, ctx.User, opt) createRepo(ctx, ctx.User, opt)
@ -177,15 +175,15 @@ func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
org, err := models.GetOrgByName(ctx.Params(":org")) org, err := models.GetOrgByName(ctx.Params(":org"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Error(404) ctx.APIError(422, "", err)
} else { } else {
ctx.Error(500) ctx.APIError(500, "GetOrgByName", err)
} }
return return
} }
if !org.IsOwnedBy(ctx.User.Id) { if !org.IsOwnedBy(ctx.User.Id) {
ctx.Error(403) ctx.APIError(403, "", "Given user is not owner of organization.")
return return
} }
createRepo(ctx, org, opt) createRepo(ctx, org, opt)
@ -198,9 +196,9 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
org, err := models.GetUserByID(form.Uid) org, err := models.GetUserByID(form.Uid)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.HandleAPI(422, err) ctx.APIError(422, "", err)
} else { } else {
ctx.HandleAPI(500, err) ctx.APIError(500, "GetUserByID", err)
} }
return return
} }
@ -208,14 +206,14 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
} }
if ctx.HasError() { if ctx.HasError() {
ctx.HandleAPI(422, ctx.GetErrMsg()) ctx.APIError(422, "", ctx.GetErrMsg())
return return
} }
if ctxUser.IsOrganization() { if ctxUser.IsOrganization() {
// Check ownership of organization. // Check ownership of organization.
if !ctxUser.IsOwnedBy(ctx.User.Id) { if !ctxUser.IsOwnedBy(ctx.User.Id) {
ctx.HandleAPI(403, "Given user is not owner of organization.") ctx.APIError(403, "", "Given user is not owner of organization.")
return return
} }
} }
@ -227,7 +225,7 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
strings.HasPrefix(form.CloneAddr, "git://") { strings.HasPrefix(form.CloneAddr, "git://") {
u, err := url.Parse(form.CloneAddr) u, err := url.Parse(form.CloneAddr)
if err != nil { if err != nil {
ctx.HandleAPI(422, err) ctx.APIError(422, "", err)
return return
} }
if len(form.AuthUsername) > 0 || len(form.AuthPassword) > 0 { if len(form.AuthUsername) > 0 || len(form.AuthPassword) > 0 {
@ -235,7 +233,7 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
} }
remoteAddr = u.String() remoteAddr = u.String()
} else if !com.IsDir(remoteAddr) { } else if !com.IsDir(remoteAddr) {
ctx.HandleAPI(422, "Invalid local path, it does not exist or not a directory.") ctx.APIError(422, "", "Invalid local path, it does not exist or not a directory.")
return return
} }
@ -246,7 +244,7 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
log.Error(4, "DeleteRepository: %v", errDelete) log.Error(4, "DeleteRepository: %v", errDelete)
} }
} }
ctx.HandleAPI(500, err) ctx.APIError(500, "MigrateRepository", err)
return return
} }
@ -254,13 +252,13 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
ctx.JSON(201, ToApiRepository(ctxUser, repo, api.Permission{true, true, true})) ctx.JSON(201, ToApiRepository(ctxUser, repo, api.Permission{true, true, true}))
} }
func RemoveRepo(ctx *middleware.Context) { func DeleteRepo(ctx *middleware.Context) {
user, err := models.GetUserByName(ctx.Params(":owner")) user, err := models.GetUserByName(ctx.Params(":username"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.HandleAPI(404, err) ctx.APIError(422, "", err)
} else { } else {
ctx.JSON(500, &base.ApiJsonErr{"GetUserByName: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetUserByName", err)
} }
return return
} }
@ -268,21 +266,20 @@ func RemoveRepo(ctx *middleware.Context) {
repo, err := models.GetRepositoryByName(user.Id, ctx.Params(":reponame")) repo, err := models.GetRepositoryByName(user.Id, ctx.Params(":reponame"))
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
ctx.HandleAPI(404, err) ctx.Error(404)
} else { } else {
ctx.JSON(500, &base.ApiJsonErr{"GetRepositoryByName: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetRepositoryByName", err)
} }
return return
} }
if user.IsOrganization() && !user.IsOwnedBy(ctx.User.Id) { if user.IsOrganization() && !user.IsOwnedBy(ctx.User.Id) {
ctx.HandleAPI(403, "Given user is not owner of organization.") ctx.APIError(403, "", "Given user is not owner of organization.")
return return
} }
if err := models.DeleteRepository(user.Id, repo.ID); err != nil { if err := models.DeleteRepository(user.Id, repo.ID); err != nil {
log.Error(4, "DeleteRespository: %v:", err) ctx.APIError(500, "DeleteRepository", err)
ctx.HandleAPI(500, err)
return return
} }

@ -6,7 +6,6 @@ package v1
import ( import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/routers/repo" "github.com/gogits/gogs/routers/repo"
@ -23,12 +22,12 @@ func GetRepoRawFile(ctx *middleware.Context) {
if err == git.ErrNotExist { if err == git.ErrNotExist {
ctx.Error(404) ctx.Error(404)
} else { } else {
ctx.JSON(500, &base.ApiJsonErr{"GetBlobByPath: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetBlobByPath", err)
} }
return return
} }
if err = repo.ServeBlob(ctx, blob); err != nil { if err = repo.ServeBlob(ctx, blob); err != nil {
ctx.JSON(500, &base.ApiJsonErr{"ServeBlob: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "ServeBlob", err)
} }
} }
@ -36,7 +35,7 @@ func GetRepoArchive(ctx *middleware.Context) {
repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame")) repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
gitRepo, err := git.OpenRepository(repoPath) gitRepo, err := git.OpenRepository(repoPath)
if err != nil { if err != nil {
ctx.Handle(500, "RepoAssignment Invalid repo: "+repoPath, err) ctx.APIError(500, "OpenRepository", err)
return return
} }
ctx.Repo.GitRepo = gitRepo ctx.Repo.GitRepo = gitRepo

@ -13,7 +13,6 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
) )
@ -47,7 +46,7 @@ func ToApiHook(repoLink string, w *models.Webhook) *api.Hook {
func ListRepoHooks(ctx *middleware.Context) { func ListRepoHooks(ctx *middleware.Context) {
hooks, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.ID) hooks, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.JSON(500, &base.ApiJsonErr{"GetWebhooksByRepoId: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetWebhooksByRepoId", err)
return return
} }
@ -62,17 +61,17 @@ func ListRepoHooks(ctx *middleware.Context) {
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook // https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook
func CreateRepoHook(ctx *middleware.Context, form api.CreateHookOption) { func CreateRepoHook(ctx *middleware.Context, form api.CreateHookOption) {
if !models.IsValidHookTaskType(form.Type) { if !models.IsValidHookTaskType(form.Type) {
ctx.JSON(422, &base.ApiJsonErr{"invalid hook type", base.DOC_URL}) ctx.APIError(422, "", "Invalid hook type")
return return
} }
for _, name := range []string{"url", "content_type"} { for _, name := range []string{"url", "content_type"} {
if _, ok := form.Config[name]; !ok { if _, ok := form.Config[name]; !ok {
ctx.JSON(422, &base.ApiJsonErr{"missing config option: " + name, base.DOC_URL}) ctx.APIError(422, "", "Missing config option: "+name)
return return
} }
} }
if !models.IsValidHookContentType(form.Config["content_type"]) { if !models.IsValidHookContentType(form.Config["content_type"]) {
ctx.JSON(422, &base.ApiJsonErr{"invalid content type", base.DOC_URL}) ctx.APIError(422, "", "Invalid content type")
return return
} }
@ -97,7 +96,7 @@ func CreateRepoHook(ctx *middleware.Context, form api.CreateHookOption) {
if w.HookTaskType == models.SLACK { if w.HookTaskType == models.SLACK {
channel, ok := form.Config["channel"] channel, ok := form.Config["channel"]
if !ok { if !ok {
ctx.JSON(422, &base.ApiJsonErr{"missing config option: channel", base.DOC_URL}) ctx.APIError(422, "", "Missing config option: channel")
return return
} }
meta, err := json.Marshal(&models.SlackMeta{ meta, err := json.Marshal(&models.SlackMeta{
@ -107,17 +106,17 @@ func CreateRepoHook(ctx *middleware.Context, form api.CreateHookOption) {
Color: form.Config["color"], Color: form.Config["color"],
}) })
if err != nil { if err != nil {
ctx.JSON(500, &base.ApiJsonErr{"slack: JSON marshal failed: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "slack: JSON marshal failed", err)
return return
} }
w.Meta = string(meta) w.Meta = string(meta)
} }
if err := w.UpdateEvent(); err != nil { if err := w.UpdateEvent(); err != nil {
ctx.JSON(500, &base.ApiJsonErr{"UpdateEvent: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "UpdateEvent", err)
return return
} else if err := models.CreateWebhook(w); err != nil { } else if err := models.CreateWebhook(w); err != nil {
ctx.JSON(500, &base.ApiJsonErr{"CreateWebhook: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "CreateWebhook", err)
return return
} }
@ -128,7 +127,7 @@ func CreateRepoHook(ctx *middleware.Context, form api.CreateHookOption) {
func EditRepoHook(ctx *middleware.Context, form api.EditHookOption) { func EditRepoHook(ctx *middleware.Context, form api.EditHookOption) {
w, err := models.GetWebhookByID(ctx.ParamsInt64(":id")) w, err := models.GetWebhookByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
ctx.JSON(500, &base.ApiJsonErr{"GetWebhookById: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetWebhookById", err)
return return
} }
@ -138,7 +137,7 @@ func EditRepoHook(ctx *middleware.Context, form api.EditHookOption) {
} }
if ct, ok := form.Config["content_type"]; ok { if ct, ok := form.Config["content_type"]; ok {
if !models.IsValidHookContentType(ct) { if !models.IsValidHookContentType(ct) {
ctx.JSON(422, &base.ApiJsonErr{"invalid content type", base.DOC_URL}) ctx.APIError(422, "", "Invalid content type")
return return
} }
w.ContentType = models.ToHookContentType(ct) w.ContentType = models.ToHookContentType(ct)
@ -153,7 +152,7 @@ func EditRepoHook(ctx *middleware.Context, form api.EditHookOption) {
Color: form.Config["color"], Color: form.Config["color"],
}) })
if err != nil { if err != nil {
ctx.JSON(500, &base.ApiJsonErr{"slack: JSON marshal failed: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "slack: JSON marshal failed", err)
return return
} }
w.Meta = string(meta) w.Meta = string(meta)
@ -171,7 +170,7 @@ func EditRepoHook(ctx *middleware.Context, form api.EditHookOption) {
w.Create = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_CREATE)) w.Create = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_CREATE))
w.Push = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_PUSH)) w.Push = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_PUSH))
if err = w.UpdateEvent(); err != nil { if err = w.UpdateEvent(); err != nil {
ctx.JSON(500, &base.ApiJsonErr{"UpdateEvent: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "UpdateEvent", err)
return return
} }
@ -180,7 +179,7 @@ func EditRepoHook(ctx *middleware.Context, form api.EditHookOption) {
} }
if err := models.UpdateWebhook(w); err != nil { if err := models.UpdateWebhook(w); err != nil {
ctx.JSON(500, &base.ApiJsonErr{"UpdateWebhook: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "UpdateWebhook", err)
return return
} }

@ -10,7 +10,6 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
) )
@ -69,7 +68,7 @@ func GetUserInfo(ctx *middleware.Context) {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Error(404) ctx.Error(404)
} else { } else {
ctx.JSON(500, &base.ApiJsonErr{"GetUserByName: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "GetUserByName", err)
} }
return return
} }

@ -8,7 +8,6 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
) )
@ -16,7 +15,7 @@ import (
func ListAccessTokens(ctx *middleware.Context) { func ListAccessTokens(ctx *middleware.Context) {
tokens, err := models.ListAccessTokens(ctx.User.Id) tokens, err := models.ListAccessTokens(ctx.User.Id)
if err != nil { if err != nil {
ctx.JSON(500, &base.ApiJsonErr{"ListAccessTokens: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "ListAccessTokens", err)
return return
} }
@ -38,7 +37,7 @@ func CreateAccessToken(ctx *middleware.Context, form CreateAccessTokenForm) {
Name: form.Name, Name: form.Name,
} }
if err := models.NewAccessToken(t); err != nil { if err := models.NewAccessToken(t); err != nil {
ctx.JSON(500, &base.ApiJsonErr{"NewAccessToken: " + err.Error(), base.DOC_URL}) ctx.APIError(500, "NewAccessToken", err)
return return
} }
ctx.JSON(201, &api.AccessToken{t.Name, t.Sha1}) ctx.JSON(201, &api.AccessToken{t.Name, t.Sha1})

@ -1 +1 @@
0.6.16.1007 Beta 0.6.16.1008 Beta
Loading…
Cancel
Save