internal/ethapi: add errorCode to revert error

This commit is contained in:
Marius van der Wijden
2020-05-28 11:27:20 +02:00
committed by Péter Szilágyi
parent cc37ce796b
commit d9b4bc76d4
2 changed files with 10 additions and 3 deletions

View File

@ -434,9 +434,11 @@ func (b *bridge) Send(call jsre.Call) (goja.Value, error) {
}
}
case rpc.Error:
setError(resp, err.ErrorCode(), err.Error())
case rpc.DataError:
resp.Set("error", map[string]interface{}{"code": -32603, "message": err.Error(), "data": err.ErrorData()})
errMap := map[string]interface{}{"code": err.ErrorCode(), "message": err.Error()}
if dataErr, ok := err.(rpc.DataError); ok {
errMap["data"] = dataErr.ErrorData()
}
resp.Set("error", errMap)
default:
setError(resp, -32603, err.Error())
}

View File

@ -868,6 +868,7 @@ var _ rpc.DataError = (*revertError)(nil)
type revertError struct {
err string // The error string
code int // optional error code
errData interface{} // additional data
}
@ -875,6 +876,10 @@ func (e revertError) Error() string {
return e.err
}
func (e revertError) ErrorCode() int {
return e.code
}
func (e revertError) ErrorData() interface{} {
return e.errData
}