<commit_before>const util = require('util');

const errorLevels = {
	debug: 0,
	info: 1,
	warn: 2,
	error: 3,
	fatal: 4
};

const config = {
	handlers: {
		debug: defaultHandler,
		info: defaultHandler,
		warn: defaultHandler,
		error: defaultHandler,
		fatal: defaultHandler
	},

	httpStatusMap: {},
	minLogLevel: 0
};

function defaultHandler(level, error) {
	if (errorLevels[level] < config.minLogLevel)
		return;

	var message = level + ':' + JSON.stringify(error);

	var method = level == 'fatal' ? 'error' : level;
	if (typeof console[method] === 'function')
		console[method](message);
	else
		console.log(message);
}

function CuvvaError(code, reasons, meta) {
	if (!(this instanceof CuvvaError))
		return new CuvvaError(code, reasons, meta);

	if (!Array.isArray(reasons)) {
		meta = reasons;
		reasons = void 0;
	}

	CuvvaError.super_(code);
	Error.captureStackTrace(this, this.constructor);

	Object.defineProperty(this, 'name', { get: function () { return 'CuvvaError'; } });
	Object.defineProperty(this, 'message', { get: function () { return this.code; } });

	this.code = code;
	this.meta = meta;
	this.reasons = reasons;
}

util.inherits(CuvvaError, Error);
module.exports.Error = CuvvaError;

function handleError(level, error) {
	if (!config.handlers[level])
		return;

	config.handlers[level](level, error);
}

module.exports.setHandler = function (level, handler) {
	if (typeof handler === 'undefined') {
		handler = level;

		if (typeof handler !== 'function')
			throw new Error('Handler is not a function');

		for (var prop in config.handlers)
			config.handlers[prop] = handler;

		return;
	}

	if (typeof handler !== 'function')<commit_msg>Set HTTP status on error object<commit_after>const util = require('util');

const errorLevels = {
	debug: 0,
	info: 1,
	warn: 2,
	error: 3,
	fatal: 4
};

const config = {
	handlers: {
		debug: defaultHandler,
		info: defaultHandler,
		warn: defaultHandler,
		error: defaultHandler,
		fatal: defaultHandler
	},

	httpStatusMap: {},
	minLogLevel: 0
};

function defaultHandler(level, error) {
	if (errorLevels[level] < config.minLogLevel)
		return;

	var message = level + ':' + JSON.stringify(error);

	var method = level == 'fatal' ? 'error' : level;
	if (typeof console[method] === 'function')
		console[method](message);
	else
		console.log(message);
}

function CuvvaError(code, reasons, meta) {
	if (!(this instanceof CuvvaError))
		return new CuvvaError(code, reasons, meta);

	if (!Array.isArray(reasons)) {
		meta = reasons;
		reasons = void 0;
	}

	CuvvaError.super_(code);
	Error.captureStackTrace(this, this.constructor);

	Object.defineProperty(this, 'name', { get: function () { return 'CuvvaError'; } });
	Object.defineProperty(this, 'message', { get: function () { return this.code; } });

	this.code = code;
	this.httpStatus = config.httpStatusMap[code];
	this.meta = meta;
	this.reasons = reasons;
}

util.inherits(CuvvaError, Error);
module.exports.Error = CuvvaError;

function handleError(level, error) {
	if (!config.handlers[level])
		return;

	config.handlers[level](level, error);
}

module.exports.setHandler = function (level, handler) {
	if (typeof handler === 'undefined') {
		handler = level;

		if (typeof handler !== 'function')
			throw new Error('Handler is not a function');

		for (var prop in config.handlers)
			config.handlers[prop] = handler;

		return;
	}

	if (typeof handler !== 'function')
{'fraction_non_alphanumeric': 0.1489549602590521, 'fraction_numerical': 0.004121283485428319, 'mean_word_length': 4.534201954397394, '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': '2299114', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1130, 'n_words': 288}