dcbot/internal/domain/error.go
Dawid Wysokiński 58f73e9ca8
All checks were successful
continuous-integration/drone/push Build is passing
feat: add a new command - /monitor create (#21)
Reviewed-on: #21
2022-10-23 06:20:48 +00:00

64 lines
994 B
Go

package domain
import (
"errors"
"fmt"
)
var (
ErrNothingToUpdate = errors.New("nothing to update")
ErrRequired = errors.New("cannot be blank")
)
type ErrorCode uint8
const (
ErrorCodeUnknown ErrorCode = iota
ErrorCodeEntityNotFound
ErrorCodeValidationError
ErrorCodeAlreadyExists
)
type UserError interface {
error
UserError() string
Code() ErrorCode
}
type ValidationError struct {
Field string
Err error
}
func (e ValidationError) Error() string {
return fmt.Sprintf("%s: %s", e.Field, e.Err)
}
func (e ValidationError) UserError() string {
return e.Error()
}
func (e ValidationError) Code() ErrorCode {
return ErrorCodeValidationError
}
func (e ValidationError) Unwrap() error {
return e.Err
}
type MinError struct {
Min int
}
func (e MinError) Error() string {
return fmt.Sprintf("must be no less than %d", e.Min)
}
func (e MinError) UserError() string {
return e.Error()
}
func (e MinError) Code() ErrorCode {
return ErrorCodeValidationError
}