Repository: go-gitea/gitea
File: routers/api/v1/packages/package.go (Go)

Code before:
	pkg, err := packages.GetPackageByName(ctx, ctx.ContextUser.ID, packages.Type(ctx.PathParam("type")), ctx.PathParam("name"))
	if err != nil {
		if errors.Is(err, util.ErrNotExist) {
			ctx.Error(http.StatusNotFound, "GetPackageByName", err)
		} else {
			ctx.Error(http.StatusInternalServerError, "GetPackageByName", err)
		}
		return
	}

	repo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ctx.PathParam("repo_name"))
	if err != nil {
		if errors.Is(err, util.ErrNotExist) {
			ctx.Error(http.StatusNotFound, "GetRepositoryByName", err)
		} else {
			ctx.Error(http.StatusInternalServerError, "GetRepositoryByName", err)
		}
		return
	}

	err = packages_service.LinkToRepository(ctx, pkg, repo, ctx.Doer)
	if err != nil {
		if errors.Is(err, util.ErrNotExist) {
			ctx.Error(http.StatusNotFound, "GetPackageByName", err)
		} else {
			ctx.Error(http.StatusInternalServerError, "GetPackageByName", err)
		}
		return
	}
	ctx.Status(http.StatusCreated)
}

// UnlinkPackage sets a repository link for a package
func UnlinkPackage(ctx *context.APIContext) {
	// swagger:operation POST /packages/{owner}/{type}/{name}/-/unlink package unlinkPackage
	// ---
	// summary: Unlink a package from a repository
	// parameters:
	// - name: owner
	//   in: path
	//   description: owner of the package
	//   type: string
	//   required: true
	// - name: type
	//   in: path
	//   description: type of the package
	//   type: string
	//   required: true
	// - name: name
	//   in: path
	//   description: name of the package

Review comment (suggestion):
```suggestion
			ctx.Error(http.StatusInternalServerError, "LinkToRepository", err)
```

Code after:
	pkg, err := packages.GetPackageByName(ctx, ctx.ContextUser.ID, packages.Type(ctx.PathParam("type")), ctx.PathParam("name"))
	if err != nil {
		if errors.Is(err, util.ErrNotExist) {
			ctx.Error(http.StatusNotFound, "GetPackageByName", err)
		} else {
			ctx.Error(http.StatusInternalServerError, "GetPackageByName", err)
		}
		return
	}

	repo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ctx.PathParam("repo_name"))
	if err != nil {
		if errors.Is(err, util.ErrNotExist) {
			ctx.Error(http.StatusNotFound, "GetRepositoryByName", err)
		} else {
			ctx.Error(http.StatusInternalServerError, "GetRepositoryByName", err)
		}
		return
	}

	err = packages_service.LinkToRepository(ctx, pkg, repo, ctx.Doer)
	if err != nil {
		switch {
		case errors.Is(err, util.ErrInvalidArgument):
			ctx.Error(http.StatusBadRequest, "LinkToRepository", err)
		case errors.Is(err, util.ErrPermissionDenied):
			ctx.Error(http.StatusForbidden, "LinkToRepository", err)
		default:
			ctx.Error(http.StatusInternalServerError, "LinkToRepository", err)
		}
		return
	}
	ctx.Status(http.StatusCreated)
}

// UnlinkPackage sets a repository link for a package
func UnlinkPackage(ctx *context.APIContext) {
	// swagger:operation POST /packages/{owner}/{type}/{name}/-/unlink package unlinkPackage
	// ---
	// summary: Unlink a package from a repository
	// parameters:
	// - name: owner
	//   in: path
	//   description: owner of the package
	//   type: string
	//   required: true
	// - name: type
	//   in: path
	//   description: type of the package
	//   type: string
	//   required: true