Files
sxchnge/backend/shared/errors/classified.go

49 lines
886 B
Go

package merrors
import "strings"
type classifiedError struct {
base error
code error
msg string
reason string
publicMessage bool
argumentNames []string
}
func (e classifiedError) Error() string {
if e.publicMessage {
msg := strings.TrimSpace(e.msg)
if msg != "" {
return msg
}
if e.code != nil {
return e.code.Error()
}
if e.base != nil {
return e.base.Error()
}
return ""
}
return Wrap(e.base, e.msg).Error()
}
func (e classifiedError) Unwrap() []error {
causes := make([]error, 0, 2)
if e.base != nil {
causes = append(causes, e.base)
}
if e.code != nil {
causes = append(causes, e.code)
}
return causes
}
func (e classifiedError) Reason() string {
return strings.TrimSpace(e.reason)
}
func (e classifiedError) InvalidArgumentFields() []string {
return append([]string(nil), e.argumentNames...)
}