forked from longtao.wu/droboticflow
37 lines
1.3 KiB
Go
37 lines
1.3 KiB
Go
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.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.ErrDuplicateUserEmail) {
|
|
renderValidationError(writer, validationIssue{Field: "email", Message: "email must be unique"})
|
|
return
|
|
}
|
|
renderError(writer, http.StatusInternalServerError, err)
|
|
}
|