Call to Socket.IO from register.js returning err, as an empty object { }

  • I'm making a call from register.js to using the following function

    function validateInviteCode(code, use, callback) {
    	callback = callback || function() {};
    	var invite_code_notify = $('#invite_code_notify');
    	if (!code.includes(':') || code.split(':')[1].length != 8) {
    		showError(invite_code_notify, 'Invalid invite code');
    		return callback();
    	socket.emit('plugins.invite.checkInviteCode', {
    		code: code,
    		use: use
    	}, function(err, valid) {
    		if (err) {
    			return callback();
    		if (valid) {
    			showSuccess(invite_code_notify, successIcon);
    		} else {
    			showError(invite_code_notify, 'Invalid invite code');

    and it's returning err as an empty object { }. This is my server-side listen for it:

    checkInviteCode: function (socket, data, fn) {
    checkCode(data.code, data.use, function(valid) {
    console.log(data, valid);
    fn(!socket.uid, valid);

  • Community Rep

    In your server code, looks like your responding with a boolean value !socket.uid when it expects an Error object or null. You can use a ternary operator ? : to check the uid and send the appropriate response.

    Also, the data parameter should always be a plain object, and not a literal value.

    fn(!socket.uid ? new Error("Invalid uid") : null, {valid: valid})

  • Ooops! I'm sorry haha, this headache is giving me coding troubles. Thanks!

Suggested Topics

| |