Browse Source

api/repo: fix nil error panic

pull/4248/merge
Unknwon 8 years ago
parent
commit
ec491b023f
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 10
      routers/api/v1/repo/repo.go

10
routers/api/v1/repo/repo.go

@ -167,7 +167,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
} else { } else {
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(2, "DeleteRepository: %v", err)
} }
} }
ctx.Error(500, "CreateRepository", err) ctx.Error(500, "CreateRepository", err)
@ -221,7 +221,7 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
} }
return return
} else if !org.IsOrganization() { } else if !org.IsOrganization() {
ctx.Error(403, "", err) ctx.Error(403, "", "Given user is not an organization")
return return
} }
ctxUser = org ctxUser = org
@ -235,7 +235,7 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
if ctxUser.IsOrganization() && !ctx.User.IsAdmin { if ctxUser.IsOrganization() && !ctx.User.IsAdmin {
// Check ownership of organization. // Check ownership of organization.
if !ctxUser.IsOwnedBy(ctx.User.ID) { if !ctxUser.IsOwnedBy(ctx.User.ID) {
ctx.Error(403, "", "Given user is not owner of organization.") ctx.Error(403, "", "Given user is not owner of organization")
return return
} }
} }
@ -248,7 +248,7 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
case addrErr.IsURLError: case addrErr.IsURLError:
ctx.Error(422, "", err) ctx.Error(422, "", err)
case addrErr.IsPermissionDenied: case addrErr.IsPermissionDenied:
ctx.Error(422, "", "You are not allowed to import local repositories.") ctx.Error(422, "", "You are not allowed to import local repositories")
case addrErr.IsInvalidPath: case addrErr.IsInvalidPath:
ctx.Error(422, "", "Invalid local path, it does not exist or not a directory.") ctx.Error(422, "", "Invalid local path, it does not exist or not a directory.")
default: default:
@ -270,7 +270,7 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
if err != nil { if err != nil {
if repo != nil { if repo != nil {
if errDelete := models.DeleteRepository(ctxUser.ID, repo.ID); errDelete != nil { if errDelete := models.DeleteRepository(ctxUser.ID, repo.ID); errDelete != nil {
log.Error(4, "DeleteRepository: %v", errDelete) log.Error(2, "DeleteRepository: %v", errDelete)
} }
} }
ctx.Error(500, "MigrateRepository", models.HandleMirrorCredentials(err.Error(), true)) ctx.Error(500, "MigrateRepository", models.HandleMirrorCredentials(err.Error(), true))

Loading…
Cancel
Save