source/middleware/error handler.js
function render_stack_trace(error, { markup_settings, log })
{
	// Supports custom `html` for an error
	if (error.html)
	{
		return { response_status: error.status, response_body: error.html }
	}

	// Handle `superagent` errors
	// https://github.com/visionmedia/superagent/blob/29ca1fc938b974c6623d9040a044e39dfb272fed/lib/node/response.js#L106
	if (error.response && typeof error.status === 'number')
	{
		// If the `superagent` http request returned an HTML response 
		// (possibly an error stack trace),
		// then just output that stack trace.
		if (error.response.headers['content-type']
			&& error.response.headers['content-type'].split(';')[0].trim() === 'text/html')
		{
			return { response_status: error.status, response_body: error.message }
		}
	}

	// If this error has a stack trace then it can be shown

	let stack_trace

	if (error.stack)
	{
		stack_trace = error.stack
	}
	// `superagent` errors have the `original` property 
	// for storing the initial error
	else if (error.original && error.original.stack)
	{
		stack_trace = error.original.stack
	}

	// If this error doesn't have a stack trace - do nothing
	if (!stack_trace)
	{
		return {}
	}

	// Render the error's stack trace as HTML markup
	try
	{
		return { response_body: html_stack_trace({ stack: stack_trace }, markup_settings) }
	}
	catch (error)
	{
		log.error(error)

		// If error stack trace couldn't be rendered as HTML markup,
		// then just output it as plain text.
		return { response_body: error.stack }
	}
}
function render_stack_trace(error, { markup_settings, log })
{
	// Supports custom `html` for an error
	if (error.html)
	{
		return { response_status: error.status, response_body: error.html }
	}

	// Handle `superagent` errors
	// https://github.com/visionmedia/superagent/blob/29ca1fc938b974c6623d9040a044e39dfb272fed/lib/node/response.js#L106
	if (error.response && typeof error.status === 'number')
	{
		// If the `superagent` http request returned an HTML response 
		// (possibly an error stack trace),
		// then just output that stack trace.
		if (error.response.headers['content-type']
			&& error.response.headers['content-type'].split(';')[0].trim() === 'text/html')
		{
			return { response_status: error.status, response_body: error.message }
		}
	}

	// If this error has a stack trace then it can be shown

	let stack_trace

	if (error.stack)
	{
		stack_trace = error.stack
	}
	// `superagent` errors have the `original` property 
	// for storing the initial error
	else if (error.original && error.original.stack)
	{
		stack_trace = error.original.stack
	}

	// If this error doesn't have a stack trace - do nothing
	if (!stack_trace)
	{
		return {}
	}

	// Render the error's stack trace as HTML markup
	try
	{
		return { response_body: html_stack_trace({ stack: stack_trace }, markup_settings) }
	}
	catch (error)
	{
		log.error(error)

		// If error stack trace couldn't be rendered as HTML markup,
		// then just output it as plain text.
		return { response_body: error.stack }
	}
}
function render_stack_trace ( error , { markup_settings , log } ) { // Supports custom `html` for an error if ( error . html ) { return { response_status : error . status , response_body : error . html } } // Handle `superagent` errors // https://github.com/visionmedia/superagent/blob/29ca1fc938b974c6623d9040a044e39dfb272fed/lib/node/response.js#L106 if ( error . response && typeof error . status === 'number' ) { // If the `superagent` http request returned an HTML response  // (possibly an error stack trace), // then just output that stack trace. if ( error . response . headers [ 'content-type' ] && error . response . headers [ 'content-type' ] . split ( ';' ) [ 0 ] . trim ( ) === 'text/html' ) { return { response_status : error . status , response_body : error . message } } } // If this error has a stack trace then it can be shown let stack_trace if ( error . stack ) { stack_trace = error . stack } // `superagent` errors have the `original` property  // for storing the initial error else if ( error . original && error . original . stack ) { stack_trace = error . original . stack } // If this error doesn't have a stack trace - do nothing if ( ! stack_trace ) { return { } } // Render the error's stack trace as HTML markup try { return { response_body : html_stack_trace ( { stack : stack_trace } , markup_settings ) } } catch ( error ) { log . error ( error ) // If error stack trace couldn't be rendered as HTML markup, // then just output it as plain text. return { response_body : error . stack } } }
Renders the stack trace of an error as HTML markup
Renders the stack trace of an error as HTML markup