droboticflow/internal/api/store_errors.go

29 lines
874 B
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.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)
}