rpc: extend the list of predefined RPC errors
Add a few the most common ones.
This commit is contained in:
parent
ef9eca7cce
commit
6434404081
2 changed files with 16 additions and 6 deletions
|
@ -34,6 +34,16 @@ const (
|
|||
var (
|
||||
// ErrInvalidParams represents a generic 'invalid parameters' error.
|
||||
ErrInvalidParams = NewInvalidParamsError("invalid params")
|
||||
// ErrUnknownBlock is returned if requested block is not found.
|
||||
ErrUnknownBlock = NewError(RPCErrorCode, "Unknown block", "")
|
||||
// ErrUnknownTransaction is returned if requested transaction is not found.
|
||||
ErrUnknownTransaction = NewError(RPCErrorCode, "Unknown transaction", "")
|
||||
// ErrUnknownHeader is returned when requested header is not found.
|
||||
ErrUnknownHeader = NewError(RPCErrorCode, "Unknown header", "")
|
||||
// ErrUnknownScriptContainer is returned when requested block or transaction is not found.
|
||||
ErrUnknownScriptContainer = NewError(RPCErrorCode, "Unknown script container", "")
|
||||
// ErrUnknownStateRoot is returned when requested state root is not found.
|
||||
ErrUnknownStateRoot = NewError(RPCErrorCode, "Unknown state root", "")
|
||||
// ErrAlreadyExists represents SubmitError with code -501.
|
||||
ErrAlreadyExists = NewSubmitError(-501, "Block or transaction already exists and cannot be sent repeatedly.")
|
||||
// ErrOutOfMemory represents SubmitError with code -502.
|
||||
|
|
|
@ -671,7 +671,7 @@ func (s *Server) getApplicationLog(reqParams request.Params) (interface{}, *resp
|
|||
|
||||
appExecResults, err := s.chain.GetAppExecResults(hash, trigger.All)
|
||||
if err != nil {
|
||||
return nil, response.NewRPCError("Unknown transaction or block", fmt.Sprintf("failed to locate application log: %s", err))
|
||||
return nil, response.WrapErrorWithData(response.ErrUnknownScriptContainer, fmt.Sprintf("failed to locate application log: %s", err))
|
||||
}
|
||||
return result.NewApplicationLog(hash, appExecResults, trig), nil
|
||||
}
|
||||
|
@ -1379,7 +1379,7 @@ func (s *Server) getStateRoot(ps request.Params) (interface{}, *response.Error)
|
|||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, response.NewRPCError("Unknown state root", "")
|
||||
return nil, response.ErrUnknownStateRoot
|
||||
}
|
||||
return rt, nil
|
||||
}
|
||||
|
@ -1413,7 +1413,7 @@ func (s *Server) getrawtransaction(reqParams request.Params) (interface{}, *resp
|
|||
}
|
||||
tx, height, err := s.chain.GetTransaction(txHash)
|
||||
if err != nil {
|
||||
return nil, response.NewRPCError("Unknown transaction", "")
|
||||
return nil, response.ErrUnknownTransaction
|
||||
}
|
||||
if v, _ := reqParams.Value(1).GetBoolean(); v {
|
||||
if height == math.MaxUint32 {
|
||||
|
@ -1444,7 +1444,7 @@ func (s *Server) getTransactionHeight(ps request.Params) (interface{}, *response
|
|||
|
||||
_, height, err := s.chain.GetTransaction(h)
|
||||
if err != nil || height == math.MaxUint32 {
|
||||
return nil, response.NewRPCError("Unknown transaction", "")
|
||||
return nil, response.ErrUnknownTransaction
|
||||
}
|
||||
|
||||
return height, nil
|
||||
|
@ -1478,7 +1478,7 @@ func (s *Server) getBlockSysFee(reqParams request.Params) (interface{}, *respons
|
|||
headerHash := s.chain.GetHeaderHash(num)
|
||||
block, errBlock := s.chain.GetBlock(headerHash)
|
||||
if errBlock != nil {
|
||||
return 0, response.NewRPCError("Unknown block", "")
|
||||
return 0, response.ErrUnknownBlock
|
||||
}
|
||||
|
||||
var blockSysFee int64
|
||||
|
@ -1500,7 +1500,7 @@ func (s *Server) getBlockHeader(reqParams request.Params) (interface{}, *respons
|
|||
verbose, _ := reqParams.Value(1).GetBoolean()
|
||||
h, err := s.chain.GetHeader(hash)
|
||||
if err != nil {
|
||||
return nil, response.NewRPCError("Unknown header", "")
|
||||
return nil, response.ErrUnknownHeader
|
||||
}
|
||||
|
||||
if verbose {
|
||||
|
|
Loading…
Reference in a new issue