Files
kurious/internal/domain/error.go
2023-11-23 19:13:54 +03:00

37 lines
618 B
Go

package domain
import (
"fmt"
)
const (
ErrNotImplemented SimpleError = "not implemented"
ErrUnexpectedStatus SimpleError = "unexpected status"
)
type SimpleError string
func (err SimpleError) Error() string {
return string(err)
}
type ValidationError struct {
Field string
Reason string
}
func (err *ValidationError) Error() string {
return fmt.Sprintf("field %s is not valid for reason %s", err.Field, err.Reason)
}
func NewValidationError(field, reason string) *ValidationError {
if field == "" {
panic("field not provided")
}
return &ValidationError{
Field: field,
Reason: reason,
}
}