Comparing version 4.1.0 to 4.1.1
@@ -0,1 +1,4 @@ | ||
2019/04/20 Version 4.1.1 | ||
- Respect handleError for 400 and 500 errors | ||
2019/04/15 Version 4.1.0 | ||
@@ -2,0 +5,0 @@ - Add ability to set the host in cli mode |
@@ -45,7 +45,3 @@ 'use strict'; | ||
if (statErr) { | ||
if (handleError) { | ||
status[500](res, next, { error: statErr }); | ||
} else { | ||
next(); | ||
} | ||
status[500](res, next, { error: statErr, handleError }); | ||
return; | ||
@@ -59,7 +55,3 @@ } | ||
if (readErr) { | ||
if (handleError) { | ||
status[500](res, next, { error: readErr }); | ||
} else { | ||
next(); | ||
} | ||
status[500](res, next, { error: readErr, handleError }); | ||
return; | ||
@@ -157,7 +149,3 @@ } | ||
if (err) { | ||
if (handleError) { | ||
status[500](res, next, { error: err }); | ||
} else { | ||
next(); | ||
} | ||
status[500](res, next, { error: err, handleError }); | ||
return; | ||
@@ -164,0 +152,0 @@ } |
@@ -57,2 +57,13 @@ 'use strict'; | ||
res.statusCode = 500; | ||
if (!opts.handleError && next) { | ||
next(opts.error); | ||
return; | ||
} | ||
if (res.headersSent) { | ||
res.destroy(); | ||
return; | ||
} | ||
res.setHeader('content-type', 'text/html'); | ||
@@ -80,19 +91,23 @@ const error = String(opts.error.stack || opts.error || 'No specified error'); | ||
res.statusCode = 400; | ||
res.setHeader('content-type', 'text/html'); | ||
const error = opts && opts.error ? String(opts.error) : 'Malformed request.'; | ||
const html = `${[ | ||
'<!doctype html>', | ||
'<html>', | ||
' <head>', | ||
' <meta charset="utf-8">', | ||
' <title>400 Bad Request</title>', | ||
' </head>', | ||
' <body>', | ||
' <p>', | ||
` ${he.encode(error)}`, | ||
' </p>', | ||
' </body>', | ||
'</html>', | ||
].join('\n')}\n`; | ||
res.end(html); | ||
if (typeof next === 'function') { | ||
next(); | ||
} else { | ||
res.setHeader('content-type', 'text/html'); | ||
const error = opts && opts.error ? String(opts.error) : 'Malformed request.'; | ||
const html = `${[ | ||
'<!doctype html>', | ||
'<html>', | ||
' <head>', | ||
' <meta charset="utf-8">', | ||
' <title>400 Bad Request</title>', | ||
' </head>', | ||
' <body>', | ||
' <p>', | ||
` ${he.encode(error)}`, | ||
' </p>', | ||
' </body>', | ||
'</html>', | ||
].join('\n')}\n`; | ||
res.end(html); | ||
} | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"description": "A simple static file server middleware", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"homepage": "https://github.com/jfhbrook/node-ecstatic", | ||
@@ -8,0 +8,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
317661