2023-12-20 07:03:03 +00:00
|
|
|
package domain
|
|
|
|
|
|
|
|
type ErrorCode uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
ErrorCodeUnknown ErrorCode = iota
|
2023-12-27 08:07:40 +00:00
|
|
|
ErrorCodeNotFound
|
2023-12-20 07:03:03 +00:00
|
|
|
ErrorCodeIncorrectInput
|
|
|
|
)
|
|
|
|
|
|
|
|
func (e ErrorCode) String() string {
|
|
|
|
switch e {
|
2023-12-27 08:07:40 +00:00
|
|
|
case ErrorCodeNotFound:
|
|
|
|
return "not-found"
|
2023-12-20 07:03:03 +00:00
|
|
|
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
|
|
|
|
}
|
2023-12-27 08:07:40 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|