Repository: go-gitea/gitea
File: routers/web/org/setting.go (Go)

Code before:
		return
	}

	if err := user_service.RenameUser(ctx, ctx.Org.Organization.AsUser(), newOrgName); err != nil {
		if user_model.IsErrUserAlreadyExist(err) {
			ctx.JSONError(ctx.Tr("org.form.name_been_taken", newOrgName))
		} else if db.IsErrNameReserved(err) {
			ctx.JSONError(ctx.Tr("org.form.name_reserved", newOrgName))
		} else if db.IsErrNamePatternNotAllowed(err) {
			ctx.JSONError(ctx.Tr("org.form.name_pattern_not_allowed", newOrgName))
		} else {
			log.Error("RenameOrganization: %v", err)
			ctx.JSONError(util.Iif(ctx.Doer.IsAdmin, err.Error(), string(ctx.Tr("org.settings.rename_failed"))))
		}
		return
	}

	ctx.Flash.Success(ctx.Tr("org.settings.rename_success", oldOrgName, newOrgName))
	ctx.JSONRedirect(setting.AppSubURL + "/org/" + url.PathEscape(newOrgName) + "/settings")
}

// SettingsChangeVisibilityPost response for change organization visibility
func SettingsChangeVisibilityPost(ctx *context.Context) {
	visibility := structs.VisibilityModes[ctx.FormString("visibility")]
	if !visibility.IsValid() {
		ctx.JSONError(ctx.Tr("org.settings.invalid_visibility"))
		return
	}

	if ctx.Org.Organization.Visibility == visibility {
		ctx.JSONError(ctx.Tr("org.settings.change_visibility_no_change"))
		return
	}

	if err := org_service.ChangeOrganizationVisibility(ctx, ctx.Org.Organization, visibility); err != nil {
		log.Error("ChangeOrganizationVisibility: %v", err)
		ctx.JSONError(ctx.Tr("error.occurred"))
		return
	}

	ctx.Flash.Success(ctx.Tr("org.settings.change_visibility_success", ctx.Org.Organization.Name))
	ctx.JSONRedirect(setting.AppSubURL + "/org/" + url.PathEscape(ctx.Org.Organization.Name) + "/settings")
}


Review comment (suggestion):
End users would never see such error message, so please re-use the existing `invalid_data` tranlsation

Code after:
		return
	}

	if err := user_service.RenameUser(ctx, ctx.Org.Organization.AsUser(), newOrgName); err != nil {
		if user_model.IsErrUserAlreadyExist(err) {
			ctx.JSONError(ctx.Tr("org.form.name_been_taken", newOrgName))
		} else if db.IsErrNameReserved(err) {
			ctx.JSONError(ctx.Tr("org.form.name_reserved", newOrgName))
		} else if db.IsErrNamePatternNotAllowed(err) {
			ctx.JSONError(ctx.Tr("org.form.name_pattern_not_allowed", newOrgName))
		} else {
			log.Error("RenameOrganization: %v", err)
			ctx.JSONError(util.Iif(ctx.Doer.IsAdmin, err.Error(), string(ctx.Tr("org.settings.rename_failed"))))
		}
		return
	}

	ctx.Flash.Success(ctx.Tr("org.settings.rename_success", oldOrgName, newOrgName))
	ctx.JSONRedirect(setting.AppSubURL + "/org/" + url.PathEscape(newOrgName) + "/settings")
}

// SettingsChangeVisibilityPost response for change organization visibility
func SettingsChangeVisibilityPost(ctx *context.Context) {
	visibility, ok := structs.VisibilityModes[ctx.FormString("visibility")]
	if !ok {
		ctx.Flash.Error(ctx.Tr("invalid_data", visibility))
		ctx.JSONRedirect(setting.AppSubURL + "/org/" + url.PathEscape(ctx.Org.Organization.Name) + "/settings")
		return
	}

	if ctx.Org.Organization.Visibility == visibility {
		ctx.Flash.Info(ctx.Tr("nothing_has_been_changed"))
		ctx.JSONRedirect(setting.AppSubURL + "/org/" + url.PathEscape(ctx.Org.Organization.Name) + "/settings")
		return
	}

	if err := org_service.ChangeOrganizationVisibility(ctx, ctx.Org.Organization, visibility); err != nil {
		log.Error("ChangeOrganizationVisibility: %v", err)
		ctx.JSONError(ctx.Tr("error.occurred"))
		return
	}

	ctx.Flash.Success(ctx.Tr("org.settings.change_visibility_success", ctx.Org.Organization.Name))
	ctx.JSONRedirect(setting.AppSubURL + "/org/" + url.PathEscape(ctx.Org.Organization.Name) + "/settings")
}