forked from TrueCloudLab/neoneo-go
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:
parent
c681891017
commit
5dca765bd1
3 changed files with 8 additions and 2 deletions
|
@ -62,6 +62,12 @@ func NewInternalServerError(data string, cause error) *Error {
|
||||||
return newError(-32603, http.StatusInternalServerError, "Internal error", data, cause)
|
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.
|
// Error implements the error interface.
|
||||||
func (e Error) Error() string {
|
func (e Error) Error() string {
|
||||||
return fmt.Sprintf("%s (%d) - %s - %s", e.Message, e.Code, e.Data, e.Cause)
|
return fmt.Sprintf("%s (%d) - %s - %s", e.Message, e.Code, e.Data, e.Cause)
|
||||||
|
|
|
@ -234,7 +234,7 @@ Methods:
|
||||||
if as != nil {
|
if as != nil {
|
||||||
results = wrappers.NewAssetState(as)
|
results = wrappers.NewAssetState(as)
|
||||||
} else {
|
} else {
|
||||||
results = "Invalid assetid"
|
resultsErr = NewRPCError("Unknown asset", "", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "getaccountstate":
|
case "getaccountstate":
|
||||||
|
|
|
@ -87,7 +87,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
{
|
{
|
||||||
name: "negative",
|
name: "negative",
|
||||||
params: `["602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de2"]`,
|
params: `["602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de2"]`,
|
||||||
result: func(e *executor) interface{} { return "Invalid assetid" },
|
fail: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no params",
|
name: "no params",
|
||||||
|
|
Loading…
Reference in a new issue