提交 6cb39dd3 编写于 作者: P Péter Szilágyi 提交者: GitHub

Merge pull request #3529 from fjl/console-error-fix

console: fix error message in faux JSON-RPC responses
...@@ -270,18 +270,15 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) { ...@@ -270,18 +270,15 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) {
} else { } else {
resultVal, err := JSON.Call("parse", string(result)) resultVal, err := JSON.Call("parse", string(result))
if err != nil { if err != nil {
resp = newErrorResponse(call, -32603, err.Error(), &req.Id).Object() setError(resp, -32603, err.Error())
} else { } else {
resp.Set("result", resultVal) resp.Set("result", resultVal)
} }
} }
case rpc.Error: case rpc.Error:
resp.Set("error", map[string]interface{}{ setError(resp, err.ErrorCode(), err.Error())
"code": err.ErrorCode(),
"message": err.Error(),
})
default: default:
resp = newErrorResponse(call, -32603, err.Error(), &req.Id).Object() setError(resp, -32603, err.Error())
} }
resps.Call("push", resp) resps.Call("push", resp)
} }
...@@ -300,12 +297,8 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) { ...@@ -300,12 +297,8 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) {
return response return response
} }
func newErrorResponse(call otto.FunctionCall, code int, msg string, id interface{}) otto.Value { func setError(resp *otto.Object, code int, msg string) {
// Bundle the error into a JSON RPC call response resp.Set("error", map[string]interface{}{"code": code, "message": msg})
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
} }
// throwJSException panics on an otto.Value. The Otto VM will recover from the // throwJSException panics on an otto.Value. The Otto VM will recover from the
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册