package api import ( "errors" "net/http" "droboticflow/internal/store" ) func renderOrganizationMutationError(writer http.ResponseWriter, err error) { if errors.Is(err, store.ErrDuplicateOrganizationSlug) { renderValidationError(writer, validationIssue{Field: "slug", Message: "slug must be unique"}) return } renderError(writer, http.StatusInternalServerError, err) } func renderUserMutationError(writer http.ResponseWriter, err error) { if errors.Is(err, store.ErrAcceptanceAuthorizationRequired) { renderJSON(writer, 403, map[string]string{"error": err.Error(), "code": "acceptance_authorization_required"}) return } if errors.Is(err, store.ErrAccountDeleted) { renderJSON(writer, http.StatusGone, map[string]string{"error": "账号已删除,不能修改或重新启用", "code": "account_deleted"}) return } if errors.Is(err, store.ErrSupplierDeleting) { renderJSON(writer, 409, map[string]string{"error": "供应商正在删除,不能更新账号"}) return } if errors.Is(err, store.ErrAccountMutationBusy) { renderJSON(writer, 409, map[string]string{"error": "账号正在更新,请稍后重试;持续失败请管理员检查未完成操作"}) return } if errors.Is(err, store.ErrAccountPendingTasks) { renderJSON(writer, 409, map[string]string{"error": "该账号有未完成的已领取任务,请先处理任务后再修改角色"}) return } if errors.Is(err, store.ErrSupplierUnavailable) { renderJSON(writer, 409, map[string]string{"error": "供应商已失效,请刷新后重新选择"}) return } if errors.Is(err, store.ErrUserMutationConflict) { renderJSON(writer, http.StatusConflict, map[string]string{"code": "user_changed", "error": "账号已被其他操作修改,请刷新后重试"}) return } if errors.Is(err, store.ErrLastActiveAdmin) { renderJSON(writer, http.StatusConflict, map[string]string{"code": "last_active_admin", "error": "至少保留一个可登录的管理员,请先创建或启用另一管理员"}) return } if errors.Is(err, store.ErrSupplierImmutable) { renderJSON(writer, http.StatusConflict, map[string]string{"code": "supplier_immutable", "error": "员工供应商创建后不可更改"}) return } if errors.Is(err, store.ErrDuplicateUserPhone) { renderValidationError(writer, validationIssue{Field: "phone", Message: "phone must be unique"}) return } renderError(writer, http.StatusInternalServerError, err) }