aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-01-09 19:46:15 +0800
committerGitHub <noreply@github.com>2017-01-09 19:46:15 +0800
commit6cb39dd3da6ac5923d15b54b135ae7f85385c694 (patch)
treeaf69e40a1bc841ef078532b0101747063cdcfc2e
parent88cc1ca55a57f6024bedd9499288f870d4b12df4 (diff)
parent9bab0b8a24d56acdb40ee7a575958bc189494b4e (diff)
downloaddexon-6cb39dd3da6ac5923d15b54b135ae7f85385c694.tar
dexon-6cb39dd3da6ac5923d15b54b135ae7f85385c694.tar.gz
dexon-6cb39dd3da6ac5923d15b54b135ae7f85385c694.tar.bz2
dexon-6cb39dd3da6ac5923d15b54b135ae7f85385c694.tar.lz
dexon-6cb39dd3da6ac5923d15b54b135ae7f85385c694.tar.xz
dexon-6cb39dd3da6ac5923d15b54b135ae7f85385c694.tar.zst
dexon-6cb39dd3da6ac5923d15b54b135ae7f85385c694.zip
Merge pull request #3529 from fjl/console-error-fix
console: fix error message in faux JSON-RPC responses
-rw-r--r--console/bridge.go17
1 files changed, 5 insertions, 12 deletions
diff --git a/console/bridge.go b/console/bridge.go
index 1c5bc8419..f0c59804b 100644
--- a/console/bridge.go
+++ b/console/bridge.go
@@ -270,18 +270,15 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) {
} else {
resultVal, err := JSON.Call("parse", string(result))
if err != nil {
- resp = newErrorResponse(call, -32603, err.Error(), &req.Id).Object()
+ setError(resp, -32603, err.Error())
} else {
resp.Set("result", resultVal)
}
}
case rpc.Error:
- resp.Set("error", map[string]interface{}{
- "code": err.ErrorCode(),
- "message": err.Error(),
- })
+ setError(resp, err.ErrorCode(), err.Error())
default:
- resp = newErrorResponse(call, -32603, err.Error(), &req.Id).Object()
+ setError(resp, -32603, err.Error())
}
resps.Call("push", resp)
}
@@ -300,12 +297,8 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) {
return response
}
-func newErrorResponse(call otto.FunctionCall, code int, msg string, id interface{}) otto.Value {
- // Bundle the error into a JSON RPC call response
- m := map[string]interface{}{"version": "2.0", "id": id, "error": map[string]interface{}{"code": code, msg: msg}}
- res, _ := json.Marshal(m)
- val, _ := call.Otto.Run("(" + string(res) + ")")
- return val
+func setError(resp *otto.Object, code int, msg string) {
+ resp.Set("error", map[string]interface{}{"code": code, "message": msg})
}
// throwJSException panics on an otto.Value. The Otto VM will recover from the