lib/rpc-client/failureProcess.js
function failsafe(code, tracer, serverId, msg, opts, cb) {   // eslint-disable-line
    const self = this;
    const retryTimes = opts.retryTimes || constants.DEFAULT_PARAM.FAILSAFE_RETRIES;
    const retryConnectTime = opts.retryConnectTime || constants.DEFAULT_PARAM.FAILSAFE_CONNECT_TIME;

    if (!tracer.retryTimes) {
        tracer.retryTimes = 1;
    } else {
        tracer.retryTimes += 1;
    }
    switch (code) {
    case constants.RPC_ERROR.SERVER_NOT_STARTED:
    case constants.RPC_ERROR.NO_TRAGET_SERVER:
        utils.invokeCallback(cb, new Error('rpc client is not started or cannot find remote server.'));
        break;
    case constants.RPC_ERROR.FAIL_CONNECT_SERVER:
        if (tracer.retryTimes <= retryTimes) {
            setTimeout(() => {
                self.connect(tracer, serverId, cb);
            }, retryConnectTime * tracer.retryTimes);
        } else {
            utils.invokeCallback(cb, new Error(`rpc client failed to connect to remote server: ${serverId}`));
        }
        break;
    case constants.RPC_ERROR.FAIL_FIND_MAILBOX:
    case constants.RPC_ERROR.FAIL_SEND_MESSAGE:
        if (tracer.retryTimes <= retryTimes) {
            setTimeout(() => {
                self.dispatch.call(self, tracer, serverId, msg, opts, cb);
            }, retryConnectTime * tracer.retryTimes);
        } else {
            utils.invokeCallback(cb, new Error(`rpc client failed to send message to remote server: ${serverId}`));
        }
        break;
    case constants.RPC_ERROR.FILTER_ERROR:
        utils.invokeCallback(cb, new Error('rpc client filter encounters error.'));
        break;
    default:
        utils.invokeCallback(cb, new Error('rpc client unknown error.'));
    }
}
function failsafe(code, tracer, serverId, msg, opts, cb) {   // eslint-disable-line
    const self = this;
    const retryTimes = opts.retryTimes || constants.DEFAULT_PARAM.FAILSAFE_RETRIES;
    const retryConnectTime = opts.retryConnectTime || constants.DEFAULT_PARAM.FAILSAFE_CONNECT_TIME;

    if (!tracer.retryTimes) {
        tracer.retryTimes = 1;
    } else {
        tracer.retryTimes += 1;
    }
    switch (code) {
    case constants.RPC_ERROR.SERVER_NOT_STARTED:
    case constants.RPC_ERROR.NO_TRAGET_SERVER:
        utils.invokeCallback(cb, new Error('rpc client is not started or cannot find remote server.'));
        break;
    case constants.RPC_ERROR.FAIL_CONNECT_SERVER:
        if (tracer.retryTimes <= retryTimes) {
            setTimeout(() => {
                self.connect(tracer, serverId, cb);
            }, retryConnectTime * tracer.retryTimes);
        } else {
            utils.invokeCallback(cb, new Error(`rpc client failed to connect to remote server: ${serverId}`));
        }
        break;
    case constants.RPC_ERROR.FAIL_FIND_MAILBOX:
    case constants.RPC_ERROR.FAIL_SEND_MESSAGE:
        if (tracer.retryTimes <= retryTimes) {
            setTimeout(() => {
                self.dispatch.call(self, tracer, serverId, msg, opts, cb);
            }, retryConnectTime * tracer.retryTimes);
        } else {
            utils.invokeCallback(cb, new Error(`rpc client failed to send message to remote server: ${serverId}`));
        }
        break;
    case constants.RPC_ERROR.FILTER_ERROR:
        utils.invokeCallback(cb, new Error('rpc client filter encounters error.'));
        break;
    default:
        utils.invokeCallback(cb, new Error('rpc client unknown error.'));
    }
}
function failsafe ( code , tracer , serverId , msg , opts , cb ) { // eslint-disable-line const self = this ; const retryTimes = opts . retryTimes || constants . DEFAULT_PARAM . FAILSAFE_RETRIES ; const retryConnectTime = opts . retryConnectTime || constants . DEFAULT_PARAM . FAILSAFE_CONNECT_TIME ; if ( ! tracer . retryTimes ) { tracer . retryTimes = 1 ; } else { tracer . retryTimes += 1 ; } switch ( code ) { case constants . RPC_ERROR . SERVER_NOT_STARTED : case constants . RPC_ERROR . NO_TRAGET_SERVER : utils . invokeCallback ( cb , new Error ( 'rpc client is not started or cannot find remote server.' ) ) ; break ; case constants . RPC_ERROR . FAIL_CONNECT_SERVER : if ( tracer . retryTimes <= retryTimes ) { setTimeout ( ( ) => { self . connect ( tracer , serverId , cb ) ; } , retryConnectTime * tracer . retryTimes ) ; } else { utils . invokeCallback ( cb , new Error ( ` ${ serverId } ` ) ) ; } break ; case constants . RPC_ERROR . FAIL_FIND_MAILBOX : case constants . RPC_ERROR . FAIL_SEND_MESSAGE : if ( tracer . retryTimes <= retryTimes ) { setTimeout ( ( ) => { self . dispatch . call ( self , tracer , serverId , msg , opts , cb ) ; } , retryConnectTime * tracer . retryTimes ) ; } else { utils . invokeCallback ( cb , new Error ( ` ${ serverId } ` ) ) ; } break ; case constants . RPC_ERROR . FILTER_ERROR : utils . invokeCallback ( cb , new Error ( 'rpc client filter encounters error.' ) ) ; break ; default : utils . invokeCallback ( cb , new Error ( 'rpc client unknown error.' ) ) ; } }
Failsafe rpc failure process.

@param code {Number} error code number.
@param tracer {Object} current rpc tracer.
@param serverId {String} rpc remote target server id.
@param msg {Object} rpc message.
@param opts {Object} rpc client options.
@param cb {Function} user rpc callback.

@api private
Failsafe rpc failure process .