<commit_before>var _  = require('lodash');
var argy = require('argy');
var debug = require('debug')('monoxide:rest');

module.exports = function(finish, o) {
	/**
	* @static monoxide.express
	*/
	o.express = {};
	o.express._defaults = {
		count: true,
		get: true,
		query: true,
		search: true,
		create: false,
		save: false,
		delete: false,
		meta: false,
	};


	/**
	* Function to use when sending an error to the browser
	* NOTE: This function will first look for a res.sendError(code, text) function and use that if it finds one. Otherwise it will default to res.status(code).send(text).end()
	* @param {Object} res The response object
	* @param {number} code A valida HTTP return code
	* @param {*} [err] Optional error text / error object to report
	*/
	o.express.sendError = function(res, code, err) {
		if (res.sendError) {
			res.sendError(code, err);
		} else {
			res.sendStatus(code);
		}
	};

	/**
	* Set the default settings used when calling other monoxide.express.middleware functions
	* The provided settings will be merged with the existing defaults, so its possible to call this function multiple times to override previous invocations
	* NOTE: This will only effect functions called AFTER it was invoked.
	*
	* @name monoxide.express.defaults
	*
	* @param {string} [model] The model name to bind to (this can also be specified as settings.collection)
	* @param {Object} [settings] Middleware settings
	* @returns {monoxide} This chainable monoxide instance
	*
	* @example
	* // Enable saving globally
	* monoxide.express.defaults({save: true});
	*
	* @example
	* // Add a middleware function to all delete operations (assuming the invidiual controllers dont override it)
	* monoxide.express.defaults({
	* 	delete: function(req, res, next) {
	* 		// Check the user is logged in - deny otherwise
	* 		if (!req.user) return res.status(403).send('You are not logged in').end();
	* 		next();
	* 	},
	* });
	*/<commit_msg>Better error catching<commit_after>var _  = require('lodash');
var argy = require('argy');
var debug = require('debug')('monoxide:rest');

module.exports = function(finish, o) {
	/**
	* @static monoxide.express
	*/
	o.express = {};
	o.express._defaults = {
		count: true,
		get: true,
		query: true,
		search: true,
		create: false,
		save: false,
		delete: false,
		meta: false,
	};


	/**
	* Function to use when sending an error to the browser
	* NOTE: This function will first look for a res.sendError(code, text) function and use that if it finds one. Otherwise it will default to res.status(code).send(text).end()
	* @param {Object} res The response object
	* @param {number} code A valida HTTP return code
	* @param {*} [err] Optional error text / error object to report
	*/
	o.express.sendError = function(res, code, err) {
		if (res.sendError && err) {
			res.sendError(code, err);
		} else {
			res.sendStatus(code);
		}
	};

	/**
	* Set the default settings used when calling other monoxide.express.middleware functions
	* The provided settings will be merged with the existing defaults, so its possible to call this function multiple times to override previous invocations
	* NOTE: This will only effect functions called AFTER it was invoked.
	*
	* @name monoxide.express.defaults
	*
	* @param {string} [model] The model name to bind to (this can also be specified as settings.collection)
	* @param {Object} [settings] Middleware settings
	* @returns {monoxide} This chainable monoxide instance
	*
	* @example
	* // Enable saving globally
	* monoxide.express.defaults({save: true});
	*
	* @example
	* // Add a middleware function to all delete operations (assuming the invidiual controllers dont override it)
	* monoxide.express.defaults({
	* 	delete: function(req, res, next) {
	* 		// Check the user is logged in - deny otherwise
	* 		if (!req.user) return res.status(403).send('You are not logged in').end();
	* 		next();
	* 	},
	* });
	*/
{'fraction_non_alphanumeric': 0.12175699974312869, 'fraction_numerical': 0.0015412278448497304, 'mean_word_length': 3.8372670807453417, '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': '1725119', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1196, 'n_words': 433}