mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Refactor error system (#33610)
This commit is contained in:
		| @@ -46,7 +46,7 @@ func ListUnadoptedRepositories(ctx *context.APIContext) { | ||||
| 	} | ||||
| 	repoNames, count, err := repo_service.ListUnadoptedRepositories(ctx, ctx.FormString("query"), &listOptions) | ||||
| 	if err != nil { | ||||
| 		ctx.InternalServerError(err) | ||||
| 		ctx.APIErrorInternal(err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| @@ -86,33 +86,33 @@ func AdoptRepository(ctx *context.APIContext) { | ||||
| 	ctxUser, err := user_model.GetUserByName(ctx, ownerName) | ||||
| 	if err != nil { | ||||
| 		if user_model.IsErrUserNotExist(err) { | ||||
| 			ctx.NotFound() | ||||
| 			ctx.APIErrorNotFound() | ||||
| 			return | ||||
| 		} | ||||
| 		ctx.InternalServerError(err) | ||||
| 		ctx.APIErrorInternal(err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	// check not a repo | ||||
| 	has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName) | ||||
| 	if err != nil { | ||||
| 		ctx.InternalServerError(err) | ||||
| 		ctx.APIErrorInternal(err) | ||||
| 		return | ||||
| 	} | ||||
| 	isDir, err := util.IsDir(repo_model.RepoPath(ctxUser.Name, repoName)) | ||||
| 	if err != nil { | ||||
| 		ctx.InternalServerError(err) | ||||
| 		ctx.APIErrorInternal(err) | ||||
| 		return | ||||
| 	} | ||||
| 	if has || !isDir { | ||||
| 		ctx.NotFound() | ||||
| 		ctx.APIErrorNotFound() | ||||
| 		return | ||||
| 	} | ||||
| 	if _, err := repo_service.AdoptRepository(ctx, ctx.Doer, ctxUser, repo_service.CreateRepoOptions{ | ||||
| 		Name:      repoName, | ||||
| 		IsPrivate: true, | ||||
| 	}); err != nil { | ||||
| 		ctx.InternalServerError(err) | ||||
| 		ctx.APIErrorInternal(err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| @@ -148,31 +148,31 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) { | ||||
| 	ctxUser, err := user_model.GetUserByName(ctx, ownerName) | ||||
| 	if err != nil { | ||||
| 		if user_model.IsErrUserNotExist(err) { | ||||
| 			ctx.NotFound() | ||||
| 			ctx.APIErrorNotFound() | ||||
| 			return | ||||
| 		} | ||||
| 		ctx.InternalServerError(err) | ||||
| 		ctx.APIErrorInternal(err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	// check not a repo | ||||
| 	has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName) | ||||
| 	if err != nil { | ||||
| 		ctx.InternalServerError(err) | ||||
| 		ctx.APIErrorInternal(err) | ||||
| 		return | ||||
| 	} | ||||
| 	isDir, err := util.IsDir(repo_model.RepoPath(ctxUser.Name, repoName)) | ||||
| 	if err != nil { | ||||
| 		ctx.InternalServerError(err) | ||||
| 		ctx.APIErrorInternal(err) | ||||
| 		return | ||||
| 	} | ||||
| 	if has || !isDir { | ||||
| 		ctx.NotFound() | ||||
| 		ctx.APIErrorNotFound() | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if err := repo_service.DeleteUnadoptedRepository(ctx, ctx.Doer, ctxUser, repoName); err != nil { | ||||
| 		ctx.InternalServerError(err) | ||||
| 		ctx.APIErrorInternal(err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user