From 30787e48f219b23701f660ba0b99b326ab82e997 Mon Sep 17 00:00:00 2001 From: Antoine GIRARD Date: Thu, 6 Jul 2017 15:30:19 +0200 Subject: Improve org error handling (#2117) * Improve ErrOrgNotExist type Return new error type Use good error check Use new method to check error Update tests * Fix unchanged method name report --- routers/api/v1/api.go | 6 +++--- routers/api/v1/repo/fork.go | 2 +- routers/api/v1/repo/repo.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'routers/api') diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 56bb3b0f3b..14a8d59855 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -208,12 +208,12 @@ func orgAssignment(args ...bool) macaron.Handler { var err error if assignOrg { - ctx.Org.Organization, err = models.GetUserByName(ctx.Params(":orgname")) + ctx.Org.Organization, err = models.GetOrgByName(ctx.Params(":orgname")) if err != nil { - if models.IsErrUserNotExist(err) { + if models.IsErrOrgNotExist(err) { ctx.Status(404) } else { - ctx.Error(500, "GetUserByName", err) + ctx.Error(500, "GetOrgByName", err) } return } diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go index c743aec301..44b79a6fef 100644 --- a/routers/api/v1/repo/fork.go +++ b/routers/api/v1/repo/fork.go @@ -59,7 +59,7 @@ func CreateFork(ctx *context.APIContext, form api.CreateForkOption) { } else { org, err := models.GetOrgByName(*form.Organization) if err != nil { - if err == models.ErrOrgNotExist { + if models.IsErrOrgNotExist(err) { ctx.Error(422, "", err) } else { ctx.Error(500, "GetOrgByName", err) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index e0b693a4e5..7fb828ddbc 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -156,7 +156,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) { org, err := models.GetOrgByName(ctx.Params(":org")) if err != nil { - if models.IsErrUserNotExist(err) { + if models.IsErrOrgNotExist(err) { ctx.Error(422, "", err) } else { ctx.Error(500, "GetOrgByName", err) -- cgit v1.2.3