<commit_before>/**
 * Generic Error Handler / Classifier
 *
 * Calls the appropriate custom response for a given error,
 * out of the bundled response modules: 
 * badRequest, forbidden, notFound, & serverError
 * 
 * Defaults to `res.serverError`
 * 
 * Usage:
 * ```javascript
 * if (err) return res.negotiate(err);
 * ```
 *
 * @param {*} error(s)
 *
 */

module.exports = function (err) {

	// Get access to response object (`res`)
	var res = this.res;

	if (!err) return res.serverError(new Error('Invalid usage of `res.negotiate(err)`: `err` must be defined'));
	if (!err.status || err.status < 400 || err.status >= 600) return res.serverError(new Error('Invalid usage of `res.negotiate(err)`: `err.status` must be an integer between 500 and 599'));
	
	if (err.status === 403) return res.forbidden(err);
	if (err.status === 404) return res.notFound(err);
	if (err.status >= 400 && err.status < 500) return res.badRequest(err);
	return res.serverError(err);<commit_msg>Allow weirder status codes.<commit_after>/**
 * Generic Error Handler / Classifier
 *
 * Calls the appropriate custom response for a given error,
 * out of the bundled response modules: 
 * badRequest, forbidden, notFound, & serverError
 * 
 * Defaults to `res.serverError`
 * 
 * Usage:
 * ```javascript
 * if (err) return res.negotiate(err);
 * ```
 *
 * @param {*} error(s)
 *
 */

module.exports = function (err) {

	// Get access to response object (`res`)
	var res = this.res;

	if (!err) return res.serverError(new Error('Invalid usage of `res.negotiate(err)`: `err` must be defined'));
	if (typeof err.status !== 'number') return res.serverError(new Error('Invalid usage of `res.negotiate(err)`: `err.status` must be a number.'));
	
	if (err.status === 403) return res.forbidden(err);
	if (err.status === 404) return res.notFound(err);
	if (err.status >= 400 && err.status < 500) return res.badRequest(err);
	return res.serverError(err);
{'fraction_non_alphanumeric': 0.15685252735799896, 'fraction_numerical': 0.018759770713913496, 'mean_word_length': 4.175202156334231, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '3421024', 'n_tokens_mistral': 665, 'n_tokens_neox': 600, 'n_words': 194}