code: function (error, type) {
  
        // don't send a second response
        if (responseHasBeenSent) {
          console.warn('JSON-RPC2 response has already been sent.')
          return
        }
        // notifications should not send error responses (JSON-RPC2 specs)
        if (!isMethodCall) {
          var message = (error && error.toString) ? error.toString() : undefined
          logNotificationResponseWarning(message, requestMessage)
          callback()
          return
        }
  
        // internals
        var errorObject
  
        if (error instanceof Error) {
          // serious application error
          console.warn(
            'Error in JSON-RPC2 method ' + methodName + ': ' + error.toString() + '\n'
            + error.stack
          )
          // not sending detailed error info to not expose details about server code
          errorObject = {
            code: errorCodes['APPLICATION_ERROR'],
            message: errorMessages['APPLICATION_ERROR'] + ' (Check server logs for details)'
          }
  
        } else if (typeof error === 'string') {
          // error message
          errorObject = {
            code: errorCodes[type] || errorCodes['INVALID_REQUEST'],
            message: error
          }
  
        } else if (typeof error === 'object') {
          if (error.message) {
            // error object
            errorObject = error
            if (error.code === undefined) {
              error.code = errorCodes['INVALID_REQUEST']
            }
  
          } else {
            // error data
            errorObject = {
              code: errorCodes[type] || errorCodes['INVALID_REQUEST'],
              message: errorMessages[type] || errorMessages['INVALID_REQUEST'],
              data: error
            }
          }
  
        } else {
          if (error !== undefined) {
            console.warn('Error parameter must be a string (error message) or object (error data)')
          }
          // fallback
          errorObject = errorObjects['INVALID_REQUEST']
  
        }
  
        var rpcMessage = {
          jsonrpc: '2.0',
          error: errorObject,
          id: id
        }
  
        callback(rpcMessage)
        responseHasBeenSent = true
  
      }
docs: create send error handler