Skip to content

Commit 7afe81f

Browse files
lunnytechknowlogick
authored andcommitted
fix bug when migrate repository 500 when repo is existed (#6188)
* fix bug when migrate repository 500 when repo is existed * use 409 but not 422 for error status code when not exist * translation fix
1 parent 594f591 commit 7afe81f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

routers/api/v1/repo/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
408408
RemoteAddr: remoteAddr,
409409
})
410410
if err != nil {
411+
if models.IsErrRepoAlreadyExist(err) {
412+
ctx.Error(409, "", "The repository with the same name already exists.")
413+
return
414+
}
415+
411416
err = util.URLSanitizedError(err, remoteAddr)
412417
if repo != nil {
413418
if errDelete := models.DeleteRepository(ctx.User, ctxUser.ID, repo.ID); errDelete != nil {

routers/repo/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
256256
return
257257
}
258258

259+
if models.IsErrRepoAlreadyExist(err) {
260+
ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tplMigrate, &form)
261+
return
262+
}
263+
259264
// remoteAddr may contain credentials, so we sanitize it
260265
err = util.URLSanitizedError(err, remoteAddr)
261266

0 commit comments

Comments
 (0)