Files
descrybe/apps/api/internal/catalog/errors.go
T
greeneclipse 8580c996c3 Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
2026-08-09 22:47:43 +02:00

40 lines
897 B
Go

package catalog
import "errors"
var (
ErrSystemImmutable = errors.New("system records cannot be modified or deleted")
ErrNotFound = errors.New("not found")
)
// clientError is a validation/business message safe to return to API clients.
type clientError struct {
msg string
}
func (e *clientError) Error() string { return e.msg }
// ClientMsg marks a message as safe to expose in HTTP 4xx responses.
func ClientMsg(msg string) error {
return &clientError{msg: msg}
}
// ClientError reports whether err is a known client-facing catalog error.
func ClientError(err error) (msg string, ok bool) {
if err == nil {
return "", false
}
var ce *clientError
if errors.As(err, &ce) {
return ce.msg, true
}
switch {
case errors.Is(err, ErrNotFound):
return "not found", true
case errors.Is(err, ErrSystemImmutable):
return err.Error(), true
default:
return "", false
}
}