<commit_before>import './Router'
import './Config'
import './Errors'
import './ErrorHandler'
import './Log'
import './HttpServer'
import './RouteExtension'

import Grind from 'express'

module.exports = function(parameters = { }) {
	RouteExtension()

	const routerClass = parameters.routerClass || Router
	const configClass = parameters.configClass || Config
	const errorHandlerClass = parameters.errorHandlerClass || ErrorHandler

	const grind = Grind()

	grind.env = () => process.env.NODE_ENV || 'local'
	grind.routes = new routerClass(grind)
	grind.config = new configClass(grind)
	grind.errorHandler = new errorHandlerClass(grind)
	grind.booted = false
	grind.providers = [ ]
	grind.debug = grind.config.get('app.debug', grind.env() === 'local')

	grind.boot = function() {
		if(this.booted) { return }

		for(const provider of this.providers) {
			provider(this)
		}

		this.booted = true
	}

	const listen = grind.listen

	grind.listen = function(...args) {
		this.boot()

		this.use((err, req, res, next) => {
			this.errorHandler.handle(err, req, res, next)
		})

		return listen.apply(grind, args)
	}

	return grind
}
<commit_msg>404’s are now processed through the error handler<commit_after>import './Router'
import './Config'
import './Errors'
import './ErrorHandler'
import './Log'
import './HttpServer'
import './RouteExtension'

import Grind from 'express'

module.exports = function(parameters = { }) {
	RouteExtension()

	const routerClass = parameters.routerClass || Router
	const configClass = parameters.configClass || Config
	const errorHandlerClass = parameters.errorHandlerClass || ErrorHandler

	const grind = Grind()

	grind.env = () => process.env.NODE_ENV || 'local'
	grind.routes = new routerClass(grind)
	grind.config = new configClass(grind)
	grind.errorHandler = new errorHandlerClass(grind)
	grind.booted = false
	grind.providers = [ ]
	grind.debug = grind.config.get('app.debug', grind.env() === 'local')

	grind.boot = function() {
		if(this.booted) { return }

		for(const provider of this.providers) {
			provider(this)
		}

		this.booted = true
	}

	const listen = grind.listen

	grind.listen = function(...args) {
		this.boot()

		// Register error handler
		this.use((err, req, res, next) => {
			this.errorHandler.handle(err, req, res, next)
		})

		// Register 404 handler
		this.use((req, res, next) => {
			this.errorHandler.handle(new NotFoundError, req, res, next)
		})

		return listen.apply(grind, args)
	}

	return grind
}

{'fraction_non_alphanumeric': 0.14199029126213591, 'fraction_numerical': 0.0024271844660194173, 'mean_word_length': 4.006072874493927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '6058606', 'n_tokens_mistral': 863, 'n_tokens_neox': 796, 'n_words': 191}