bouncer/internal/schema/error.go

34 lines
653 B
Go
Raw Permalink Normal View History

2023-04-24 20:52:12 +02:00
package schema
import (
"errors"
"fmt"
"github.com/qri-io/jsonschema"
)
var (
ErrSchemaNotFound = errors.New("schema not found")
ErrInvalidData = errors.New("invalid data")
)
type InvalidDataError struct {
keyErrors []jsonschema.KeyError
}
func (e *InvalidDataError) Is(err error) bool {
return err == ErrInvalidData
}
func (e *InvalidDataError) Error() string {
return fmt.Sprintf("%s: %s", ErrInvalidData.Error(), e.keyErrors)
}
func (e *InvalidDataError) KeyErrors() []jsonschema.KeyError {
return e.keyErrors
}
func NewInvalidDataError(keyErrors ...jsonschema.KeyError) *InvalidDataError {
return &InvalidDataError{keyErrors}
}