<commit_before>
var debug = require('nor-debug');
var is = require('nor-is');

/* Send errors */
module.exports = function send_error(code, obj) {

	//debug.log('here');

	if(is.obj(code) && is.undef(obj)) {
		obj = code;
		code = obj.code || undefined;
	}
	obj = obj || {};
	if(!code) {
		code = 500;
	}
	debug.assert(obj).is('object');
	debug.assert(code).is('number');
	if(!obj.code) {
		obj.code = code;
	}
	if(obj.error) {
		obj.error = 'Error '+obj.code;
	}

	return function(req, res) {
		//debug.log('here');
		res.type('application/json');
		res.send(code, JSON.stringify(obj) + '\n' );
	};
};

/* EOF */<commit_msg>Fixed sending HTTP errors<commit_after>
var debug = require('nor-debug');
var is = require('nor-is');

/* Send errors */
module.exports = function send_error(code, obj) {

	//debug.log('here');

	if(is.obj(code) && is.undef(obj)) {
		obj = code;
		code = obj.code || undefined;
	}
	obj = obj || {};
	if(!code) {
		code = 500;
	}
	debug.assert(obj).is('object');
	debug.assert(code).is('number');
	if(!obj.code) {
		obj.code = code;
	}
	if(obj.message) {
		obj.error = ''+obj.message;
		delete obj.message;
	}
	if(!obj.error) {
		obj.error = 'Error '+obj.code;
	}

	return function(req, res) {
		//debug.log('here');
		res.type('application/json');
		res.send(code, JSON.stringify(obj) + '\n' );
	};
};

/* EOF */
{'fraction_non_alphanumeric': 0.2281226626776365, 'fraction_numerical': 0.004487658937920718, 'mean_word_length': 3.46, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6405641', 'n_tokens_mistral': 559, 'n_tokens_neox': 526, 'n_words': 96}