mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
Merge pull request #1773 from nspcc-dev/detailed-rpc-error
rpc: detalize `submit*` RPC validation error
This commit is contained in:
commit
50e330a9c8
2 changed files with 12 additions and 6 deletions
|
@ -93,3 +93,9 @@ func NewSubmitError(code int64, message string) *Error {
|
|||
func (e *Error) Error() string {
|
||||
return fmt.Sprintf("%s (%d) - %s - %s", e.Message, e.Code, e.Data, e.Cause)
|
||||
}
|
||||
|
||||
// WrapErrorWithData returns copy of the given error with specified data and cause.
|
||||
// It does not modify the source error.
|
||||
func WrapErrorWithData(e *Error, data error) *Error {
|
||||
return NewError(e.Code, e.HTTPCode, e.Message, data.Error(), data)
|
||||
}
|
||||
|
|
|
@ -1235,9 +1235,9 @@ func (s *Server) submitBlock(reqParams request.Params) (interface{}, *response.E
|
|||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, core.ErrInvalidBlockIndex) || errors.Is(err, core.ErrAlreadyExists):
|
||||
return nil, response.ErrAlreadyExists
|
||||
return nil, response.WrapErrorWithData(response.ErrAlreadyExists, err)
|
||||
default:
|
||||
return nil, response.ErrValidationFailed
|
||||
return nil, response.WrapErrorWithData(response.ErrValidationFailed, err)
|
||||
}
|
||||
}
|
||||
return &result.RelayResult{
|
||||
|
@ -1273,13 +1273,13 @@ func getRelayResult(err error, hash util.Uint256) (interface{}, *response.Error)
|
|||
Hash: hash,
|
||||
}, nil
|
||||
case errors.Is(err, core.ErrAlreadyExists):
|
||||
return nil, response.ErrAlreadyExists
|
||||
return nil, response.WrapErrorWithData(response.ErrAlreadyExists, err)
|
||||
case errors.Is(err, core.ErrOOM):
|
||||
return nil, response.ErrOutOfMemory
|
||||
return nil, response.WrapErrorWithData(response.ErrOutOfMemory, err)
|
||||
case errors.Is(err, core.ErrPolicy):
|
||||
return nil, response.ErrPolicyFail
|
||||
return nil, response.WrapErrorWithData(response.ErrPolicyFail, err)
|
||||
default:
|
||||
return nil, response.ErrValidationFailed
|
||||
return nil, response.WrapErrorWithData(response.ErrValidationFailed, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue