rpc: add custom error with code -100

Fixed getassetstate method: it should return error with code -100 when
asset with specified id is not found (as in c# node).
This commit is contained in:
Anna Shaleva 2020-02-15 19:06:34 +03:00 committed by AnnaShaleva
parent c681891017
commit 5dca765bd1
3 changed files with 8 additions and 2 deletions

View file

@ -62,6 +62,12 @@ func NewInternalServerError(data string, cause error) *Error {
return newError(-32603, http.StatusInternalServerError, "Internal error", data, cause)
}
// NewRPCError creates a new error with
// code -100
func NewRPCError(message string, data string, cause error) *Error {
return newError(-100, http.StatusUnprocessableEntity, message, data, cause)
}
// Error implements the error interface.
func (e Error) Error() string {
return fmt.Sprintf("%s (%d) - %s - %s", e.Message, e.Code, e.Data, e.Cause)

View file

@ -234,7 +234,7 @@ Methods:
if as != nil {
results = wrappers.NewAssetState(as)
} else {
results = "Invalid assetid"
resultsErr = NewRPCError("Unknown asset", "", nil)
}
case "getaccountstate":

View file

@ -87,7 +87,7 @@ var rpcTestCases = map[string][]rpcTestCase{
{
name: "negative",
params: `["602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de2"]`,
result: func(e *executor) interface{} { return "Invalid assetid" },
fail: true,
},
{
name: "no params",