@@ -270,18 +270,15 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) {
270270 } else {
271271 resultVal , err := JSON .Call ("parse" , string (result ))
272272 if err != nil {
273- resp = newErrorResponse ( call , - 32603 , err .Error (), & req . Id ). Object ( )
273+ setError ( resp , - 32603 , err .Error ())
274274 } else {
275275 resp .Set ("result" , resultVal )
276276 }
277277 }
278278 case rpc.Error :
279- resp .Set ("error" , map [string ]interface {}{
280- "code" : err .ErrorCode (),
281- "message" : err .Error (),
282- })
279+ setError (resp , err .ErrorCode (), err .Error ())
283280 default :
284- resp = newErrorResponse ( call , - 32603 , err .Error (), & req . Id ). Object ( )
281+ setError ( resp , - 32603 , err .Error ())
285282 }
286283 resps .Call ("push" , resp )
287284 }
@@ -300,12 +297,8 @@ func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) {
300297 return response
301298}
302299
303- func newErrorResponse (call otto.FunctionCall , code int , msg string , id interface {}) otto.Value {
304- // Bundle the error into a JSON RPC call response
305- m := map [string ]interface {}{"version" : "2.0" , "id" : id , "error" : map [string ]interface {}{"code" : code , msg : msg }}
306- res , _ := json .Marshal (m )
307- val , _ := call .Otto .Run ("(" + string (res ) + ")" )
308- return val
300+ func setError (resp * otto.Object , code int , msg string ) {
301+ resp .Set ("error" , map [string ]interface {}{"code" : code , "message" : msg })
309302}
310303
311304// throwJSException panics on an otto.Value. The Otto VM will recover from the
0 commit comments