try new errors
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
type ApplyResult struct {
|
||||
Type string `json:"type"`
|
||||
Mutation proto.Message `json:"mutation"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Error error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type MutationRegistry interface {
|
||||
@@ -30,9 +30,23 @@ type ProtoMutationRegistry struct {
|
||||
}
|
||||
|
||||
var (
|
||||
ErrMutationNotRegistered = fmt.Errorf("mutation not registered")
|
||||
ErrMutationNotRegistered = &MutationError{
|
||||
Message: "mutation not registered",
|
||||
Code: 255,
|
||||
StatusCode: 500,
|
||||
}
|
||||
)
|
||||
|
||||
type MutationError struct {
|
||||
Message string `json:"message"`
|
||||
Code uint32 `json:"code"`
|
||||
StatusCode uint32 `json:"status_code"`
|
||||
}
|
||||
|
||||
func (m MutationError) Error() string {
|
||||
return m.Message
|
||||
}
|
||||
|
||||
// MutationOption configures additional behavior for a registered mutation.
|
||||
type MutationOption func(*mutationOptions)
|
||||
|
||||
@@ -167,11 +181,11 @@ func (r *ProtoMutationRegistry) Apply(grain any, msg ...proto.Message) ([]ApplyR
|
||||
entry, ok := r.mutationRegistry[rt]
|
||||
r.mutationRegistryMu.RUnlock()
|
||||
if !ok {
|
||||
results = append(results, ApplyResult{Error: ErrMutationNotRegistered.Error(), Type: rt.Name(), Mutation: m})
|
||||
results = append(results, ApplyResult{Error: ErrMutationNotRegistered, Type: rt.Name(), Mutation: m})
|
||||
continue
|
||||
}
|
||||
err := entry.Handle(grain, m)
|
||||
results = append(results, ApplyResult{Error: err.Error(), Type: rt.Name(), Mutation: m})
|
||||
results = append(results, ApplyResult{Error: err, Type: rt.Name(), Mutation: m})
|
||||
}
|
||||
|
||||
// if entry.updateTotals {
|
||||
|
||||
Reference in New Issue
Block a user