core/internal/domain/error.go

54 lines
761 B
Go

package domain
type ErrorCode uint8
const (
ErrorCodeUnknown ErrorCode = iota
ErrorCodeNotFound
ErrorCodeIncorrectInput
)
func (e ErrorCode) String() string {
switch e {
case ErrorCodeNotFound:
return "not-found"
case ErrorCodeIncorrectInput:
return "incorrect-input"
case ErrorCodeUnknown:
fallthrough
default:
return "unknown-error"
}
}
type Error interface {
error
Code() ErrorCode
Slug() string
}
type ErrorWithParams interface {
Error
Params() map[string]any
}
type simpleError struct {
msg string
code ErrorCode
slug string
}
var _ Error = simpleError{}
func (e simpleError) Error() string {
return e.msg
}
func (e simpleError) Code() ErrorCode {
return e.code
}
func (e simpleError) Slug() string {
return e.slug
}