1515 */
1616
1717var accepts = require ( 'accepts' )
18- var escapeHtml = require ( 'escape-html' ) ;
19- var fs = require ( 'fs' ) ;
18+ var escapeHtml = require ( 'escape-html' )
19+ var fs = require ( 'fs' )
2020var path = require ( 'path' )
2121var util = require ( 'util' )
2222
@@ -25,17 +25,17 @@ var util = require('util')
2525 * @private
2626 */
2727
28- var TEMPLATE = fs . readFileSync ( path . join ( __dirname , '/public/error.html' ) , 'utf8' )
28+ var DOUBLE_SPACE_REGEXP = / \x20 { 2 } / g
29+ var NEW_LINE_REGEXP = / \n / g
2930var STYLESHEET = fs . readFileSync ( path . join ( __dirname , '/public/style.css' ) , 'utf8' )
30- var doubleSpaceGlobalRegExp = / / g
31+ var TEMPLATE = fs . readFileSync ( path . join ( __dirname , '/public/error.html' ) , 'utf8' )
3132var inspect = util . inspect
32- var newLineGlobalRegExp = / \n / g
3333var toString = Object . prototype . toString
3434
3535/* istanbul ignore next */
3636var defer = typeof setImmediate === 'function'
3737 ? setImmediate
38- : function ( fn ) { process . nextTick ( fn . bind . apply ( fn , arguments ) ) }
38+ : function ( fn ) { process . nextTick ( fn . bind . apply ( fn , arguments ) ) }
3939
4040/**
4141 * Error handler:
@@ -62,7 +62,7 @@ var defer = typeof setImmediate === 'function'
6262 * @api public
6363 */
6464
65- exports = module . exports = function errorHandler ( options ) {
65+ exports = module . exports = function errorHandler ( options ) {
6666 // get environment
6767 var env = process . env . NODE_ENV || 'development'
6868
@@ -83,7 +83,7 @@ exports = module.exports = function errorHandler(options) {
8383 log = logerror
8484 }
8585
86- return function errorHandler ( err , req , res , next ) {
86+ return function errorHandler ( err , req , res , next ) {
8787 // respect err.statusCode
8888 if ( err . statusCode ) {
8989 res . statusCode = err . statusCode
@@ -139,42 +139,42 @@ exports = module.exports = function errorHandler(options) {
139139 res . end ( body )
140140 // json
141141 } else if ( type === 'json' ) {
142- var error = { message : err . message , stack : err . stack } ;
143- for ( var prop in err ) error [ prop ] = err [ prop ] ;
142+ var error = { message : err . message , stack : err . stack }
143+ for ( var prop in err ) error [ prop ] = err [ prop ]
144144 var json = JSON . stringify ( { error : error } , null , 2 )
145145 res . setHeader ( 'Content-Type' , 'application/json; charset=utf-8' )
146- res . end ( json ) ;
146+ res . end ( json )
147147 // plain text
148148 } else {
149149 res . setHeader ( 'Content-Type' , 'text/plain; charset=utf-8' )
150150 res . end ( str )
151151 }
152- } ;
153- } ;
152+ }
153+ }
154154
155155/**
156156 * Template title, framework authors may override this value.
157157 */
158158
159- exports . title = 'Connect' ;
159+ exports . title = 'Connect'
160160
161161/**
162162 * Escape a block of HTML, preserving whitespace.
163163 * @api private
164164 */
165165
166- function escapeHtmlBlock ( str ) {
166+ function escapeHtmlBlock ( str ) {
167167 return escapeHtml ( str )
168- . replace ( doubleSpaceGlobalRegExp , ' ' )
169- . replace ( newLineGlobalRegExp , '<br>' )
168+ . replace ( DOUBLE_SPACE_REGEXP , ' ' )
169+ . replace ( NEW_LINE_REGEXP , '<br>' )
170170}
171171
172172/**
173173 * Stringify a value.
174174 * @api private
175175 */
176176
177- function stringify ( val ) {
177+ function stringify ( val ) {
178178 var stack = val . stack
179179
180180 if ( stack ) {
@@ -193,6 +193,6 @@ function stringify(val) {
193193 * @api private
194194 */
195195
196- function logerror ( err , str ) {
197- console . error ( str )
196+ function logerror ( err , str ) {
197+ console . error ( str || err . stack )
198198}
0 commit comments