<commit_before>var apis 		= require( './apis' );
var util 		= require( './util' );
var rongrequest = require( './rongrequest' );

exports.create = function( chatRoomIDNamePairs, format, callback ) {
	var params = {};
	var chatRoomId;
	var validChatRoomId = true;
	for( var i=0; i<chatRoomIDNamePairs.length; ++i ) {
		chatRoomId = chatRoomIDNamePairs[i].id;
		if( util.validateId( chatRoomId ) ) {
			validChatRoomId = false;
			break;
		}
		var key = 'chatroom[' + chatRoomId + ']';
		params[ key ] = chatRoomIDNamePairs[i].name;
	}
	if( validChatRoomId ) {
		rongrequest.request( apis['chatroom']['create'], params, format, callback );	
	}
	else {
		callback( 'Invalid chat room id', null );
	}
}

exports.destroy = function( chatRoomIDs, format, callback ) {
	if( !util.validateIDs( chatRoomIDs ) ) {
		return callback( 'Invalid chat room id', null );
	}
	rongrequest.requestWithSameFields( apis['chatroom']['destroy'], {}, [{field:'chatroomId', values:chatRoomIDs}], format, callback );
}

exports.query = function( chatRoomIDs, format, callback ) {
	// Check the IDs.
	var valid = util.validateIDs( chatRoomIDs );
	if( !valid ) {
		callback( 'Invalid symbols in chat room id', null );
	}
	else {
		rongrequest.requestWithSameFields( apis['chatroom']['query'], {}, [{field:'chatroomId', values:chatRoomIDs}], format, callback );
	}
}
<commit_msg>Return the error object instead of a string in chat room related APIs.<commit_after>var apis 		= require( './apis' );
var util 		= require( './util' );
var rongrequest = require( './rongrequest' );
var rcResult 	= require( '../const' ).result;

exports.create = function( chatRoomIDNamePairs, format, callback ) {
	var params = {};
	var chatRoomId;
	var validChatRoomId = true;
	for( var i=0; i<chatRoomIDNamePairs.length; ++i ) {
		chatRoomId = chatRoomIDNamePairs[i].id;
		if( util.validateId( chatRoomId ) ) {
			validChatRoomId = false;
			break;
		}
		var key = 'chatroom[' + chatRoomId + ']';
		params[ key ] = chatRoomIDNamePairs[i].name;
	}
	if( validChatRoomId ) {
		rongrequest.request( apis['chatroom']['create'], params, format, callback );	
	}
	else {
		return callback( { code : rcResult.INVALID_CHATROOMID, message : rcResult.INVALID_CHATROOMID_MSG }, null );
	}
}

exports.destroy = function( chatRoomIDs, format, callback ) {
	if( !util.validateIDs( chatRoomIDs ) ) {
		return callback( { code : rcResult.INVALID_CHATROOMID, message : rcResult.INVALID_CHATROOMID_MSG }, null );
	}
	rongrequest.requestWithSameFields( apis['chatroom']['destroy'], {}, [{field:'chatroomId', values:chatRoomIDs}], format, callback );
}

exports.query = function( chatRoomIDs, format, callback ) {
	// Check the IDs.
	var valid = util.validateIDs( chatRoomIDs );
	if( !valid ) {
		callback( { code : rcResult.INVALID_CHATROOMID, message : rcResult.INVALID_CHATROOMID_MSG }, null );
	}
	else {
		rongrequest.requestWithSameFields( apis['chatroom']['query'], {}, [{field:'chatroomId', values:chatRoomIDs}], format, callback );
	}
}

{'fraction_non_alphanumeric': 0.15456989247311828, 'fraction_numerical': 0.0006720430107526882, 'mean_word_length': 4.659695817490494, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1016563', 'n_tokens_mistral': 1043, 'n_tokens_neox': 999, 'n_words': 232}