Handles ajax responses for flash notifications.
callback fn is passed with 3 params,
1. {Boolean} true if success
2. {String} message either success or error
3. {Object} json given by server
@param {Function} fn
11530
function (fn) {
            return function (response) {
                fn(response.status === "success" ? true : false, response.message, response.data);
            };
        }
951010
private void processCallback(final Callback callback) {
        try {
            JsonNode result = handleCallback(callback);
            this.getClient().completeCallback(callback, null, result);
        } catch (JsiiException e) {
            this.getClient().completeCallback(callback, e.getMessage(), null);
        }
    }
1041138
function(callback) {
  tox.on('friendRequest', function(evt) {
    console.log('Accepting friend request from ' + evt.publicKeyHex());
    // Automatically accept the request
    tox.addFriendNoRequestAsync(evt.publicKey()).then(function() {
      console.log('Successfully accepted the friend request!');
    }).catch(function(err) {
      console.error('Couldn\'t accept the friend request:', err);
    });
  });

  tox.on('friendMessage', function(evt) {
    console.log('Message from friend ' + evt.friend() + ': ' + evt.message());
    // Echo message back to friend
    tox.sendMessageAsync(evt.friend(), evt.message()).then(function(receipt) {
      console.log('Echoed message back to friend, received receipt ' + receipt);
    }).catch(function(err) {
      console.error('Couldn\'t echo message back to friend:', err);
    });
  });

  // Setup friendMessage callback to listen for groupchat invite requests
  tox.on('friendMessage', function(evt) {
    if(evt.message() === 'invite text') {
      tox.inviteAsync(evt.friend(), groupchats['text']).then(function() {
        console.log('Invited ' + evt.friend() + ' to the text groupchat');
      });
    } else if(evt.message() === 'invite av') {
      tox.inviteAsync(evt.friend(), groupchats['av']).then(function() {
        console.log('Invited ' + evt.friend() + ' to the audio/video groupchat');
      });
    }
  });

  callback();
}
398503
function postback(payload, callback)
{
  if (typeof payload.payload == 'string')
  {
    payload.payload = JSON.parse(payload.payload);
  }

  callback(null, payload);
}
341853
function _onMessage(message) {
        var response    = JSON.parse(message.data),
            msgRecord   = _messageCallbacks[response.id],
            callback    = msgRecord && msgRecord.callback,
            msgText     = (msgRecord && msgRecord.message) || "No message";

        if (msgRecord) {
            // Messages with an ID are a response to a command, fire callback
            callback(response.result, response.error);
            delete _messageCallbacks[response.id];
        } else if (response.method) {
            // Messages with a method are an event, trigger event handlers
            var domainAndMethod = response.method.split("."),
                domain = domainAndMethod[0],
                method = domainAndMethod[1];

            EventDispatcher.triggerWithArray(exports[domain], method, response.params);
        }

        // Always fire event handlers for all messages/errors
        exports.trigger("message", response);

        if (response.error) {
            exports.trigger("error", response.error, msgText);
        }
    }
483466
function handle(msg) {
  log.debug('handling msg', msg)
  var to = msg.to,
    intent = msg.intent;
  if (to && intent) {
    var reply;
    // try JSON or JSON.input as input
    try {
      reply = _.get(lib_js[to], intent)(msg)
    } catch (err) {
      try {
        reply = _.get(lib_js[to], intent)(msg.input)
      } catch (deepErr) {
        log.debug('js handle fails.', deepErr)
      }
    } finally {
      // try JSON or made-JSON output
      reply = correctReply(reply, msg)
      log.debug('reply', reply)
      if (reply.to) {
        client.emit('pass', reply)
      }
    }
  }
}
568395
function (callbackFn) {
            var self = this;
            request.post(this.options.hostAndPort + '/phantom/functions/exit', {
                    form:{
                    }
                },
                function (error, response, body) {

                    if (response && response.statusCode === 200) {    //server up
                        self.server.close();
                        callbackFn && callbackFn.call(self, true);
                    }
                    else {    //server down
                        callbackFn.call(self, false);
                    }
                });
        }
1215059
function handler ( err, data ){
      if ( callback != null ){
        callback.apply( b9, arguments );
      }
      // only emit events when there is no error
      if ( err == null ){
        b9.emit.call( b9, method, data );
      }
    }
551058
function (expressionFn, callbackFn) {
                    var self = this,
                        url = self.options.hostAndPort + '/page/functions/evaluate';

                    self.options.debug && console.log('calling url: %s', url);

                    request.post(url, {
                            form:{expressionFn:expressionFn.toString(), args:JSON.stringify(Array.prototype.slice.call(arguments, 2, arguments.length), null, 4)}
                        },
                        function (error, response, body) {
                            if (response && response.statusCode === 200) {
                                callbackFn && callbackFn.call(self, JSON.parse(body));
                            }
                            else {
                                console.error(body);
                                callbackFn && callbackFn.call(self, body);
                            }
                        });
                }
69153
function (response_type, event) {
	
		LOG.sys('handling event response [' + response_type  + ']', l_name);
		
		// go over each registered callback function and see which one responds
		for (var i=0; i < l_responders[response_type].length; i++) {
			// find the callback with matching client id
			// call callback and see whether it has been processed
			if (l_responders[response_type][i].cid === event.cid) {
				// log incoming message type & IP/port
				LOG.sys(SR.Tags.RCV + response_type + ' from ' + event.printSource() + SR.Tags.END, l_name);

				// make callback
				UTIL.safeCall(l_responders[response_type][i].onResponse, event);

				// then remove it
				l_responders[response_type].splice(i, 1);
				i--;
			}
		}
	}
546761
function handle(js,line){
    // handle message from board.
    //stream.log("handle",stream.token,line);

    var hasToken = stream.token;
    if(js.type == "token") {

      // send in event stream.
      stream.queue(js); 
      stream.token = js.token;

      if(!hasToken) {
        readycb(false,stream);
        clearTimeout(readyTimeout); 
      }
      return;
    }

    if(!stream.token) return stream.log('data from socket before auth/id token.',js);

    if(js.type == 'reply'){

      o = stream.callbacks[js.id]||{};

      if(o.id === undefined) return stream.log('got reply with no id mapping! ',js);


      var output = js.output||js.reply||"";
      var ret = js.return;// not set yet.

      if(!o.output) o.output = "";
      // handle chunked responses. they come in order.
      o.output += output;

      // soon the firmware will support returning the return int value of the scout script function/expression. it willbe the property return.
      if(ret) {
        o.return = ret;
      }

      js._cid = js.id;
      js.id = o.id;

      if(js.err || js.end) {

        delete stream.callbacks[js._cid];
        js.reply = js.output = o.output;
        js.return = o.return;
        o.cb(js.err,js)
      }

    } else if(js.type == "report" && line == stream._lastreport){
      // duplicate reports are not really useful to propagate as events because nothing changed.
      return;// stream.log('duplicate report ',line);
    } else if (js.type == "report") {
      stream._lastreport = line;
      stream.queue(js);// send report in stream.
    } else {
      stream.log('unknown message type',js);
    }
  }
638698
function(msg, callback) {
    try {
      var result = JSON.parse(msg.content);

      // the message is ack'ed on success
      // second parameter is optional for logging
      callback(null, result);
    } catch(err) {

      // the message is nack'ed on error
      callback(err);
    }
  }
422494
function (fn) {
    if (!fn || !_.isFunction(fn)) {
      var err = new Error('Please pass a valid function!');
      debug(err);
      throw err;
    }

    if (fn.length === 3) {
      this.shouldHandle = fn;
      return this;
    }

    this.shouldHandle = function (evt, saga, callback) {
      callback(null, fn(evt, saga));
    };

    var unwrappedShouldHandle = this.shouldHandle;

    this.shouldHandle = function (evt, saga, clb) {
      var wrappedCallback = function () {
        try {
          clb.apply(this, _.toArray(arguments));
        } catch (e) {
          debug(e);
          process.emit('uncaughtException', e);
        }
      };

      try {
        unwrappedShouldHandle.call(this, evt, saga, wrappedCallback);
      } catch (e) {
        debug(e);
        process.emit('uncaughtException', e);
      }
    };

    return this;
  }
933290
function (json, callback) {
        //validate input
        if (!inputValidation(json)) {
            var inputError = new SearchError('invalid input');
            callback(undefined, inputError);
            return;
        }
        //mongodb api here, then handle the response from mongodb
        database.getSentimentForNameTimeframe(json.character, json.startDate, json.endDate, function (json, err) {
            if (err) {
                callback(undefined, err);
            } else {
                callback(json);
            }
        });
    }
66818
function _stop_tracking_callback() {
            $this->_logger->entrance();

            $this->check_ajax_referer( 'stop_tracking' );

            $result = $this->stop_tracking( fs_is_network_admin() );

            if ( true === $result ) {
                self::shoot_ajax_success();
            }

            $this->_logger->api_error( $result );

            self::shoot_ajax_failure(
                sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
                ( $this->is_api_error( $result ) && isset( $result->error ) ?
                    $result->error->message :
                    var_export( $result, true ) )
            );
        }
654167
function _multiCallback(serverError, serverResponse, callback, interleave, requestedIds){
  var clientResponse = {};
  
  // Handle response errors
  _.each(serverResponse, function(data, id){
    var thisError = serverError;
    if(serverError && data.status.code !== 200){
      thisError = new Error(data.status.msgs.join('. '));
      thisError.code = data.status.code;
    }
    clientResponse[id] = {
      error:  thisError,
      data: data.data
    };
  });
  
  // Handle request level errors
  if(serverError && !serverResponse){
    _.each(requestedIds, function(id){
      if(_.isUndefined(clientResponse[id])){
        clientResponse[id] = {
          error: serverError,
          data: null
        };
      } 
    });
  }
  
  // Interleave validation errors
  if(interleave){
    _.extend(clientResponse, interleave);
  }
  
  callback(clientResponse);
}
1211790
function (msg, nodeId, ns) {
            nodeId = nodeId || "errorFlash";
            this.flashMessage(msg, nodeId, ns, true);
        }