express-mung
Advanced tools
Comparing version 0.4.1 to 0.4.2
28
index.js
@@ -11,3 +11,7 @@ 'use strict'; | ||
mung.onError = (err, req, res) => { | ||
res.status(500).json({ message: err.message }).end(); | ||
res | ||
.status(500) | ||
.set('content-language', 'en') | ||
.json({ message: err.message }) | ||
.end(); | ||
return res; | ||
@@ -19,3 +23,3 @@ }; | ||
let original = res.json; | ||
function hook (json) { | ||
function json_hook (json) { | ||
let originalJson = json; | ||
@@ -25,2 +29,4 @@ res.json = original; | ||
return res; | ||
if (res.statusCode >= 400) | ||
return original.call(this, json); | ||
@@ -52,3 +58,3 @@ // Run the munger | ||
} | ||
res.json = hook; | ||
res.json = json_hook; | ||
@@ -62,6 +68,8 @@ next && next(); | ||
let original = res.json; | ||
function hook (json) { | ||
function json_async_hook (json) { | ||
res.json = original; | ||
if (res.headersSent) | ||
return; | ||
if (res.statusCode >= 400) | ||
return original.call(this, json); | ||
try { | ||
@@ -92,3 +100,3 @@ fn(json, req, res) | ||
} | ||
res.json = hook; | ||
res.json = json_async_hook; | ||
@@ -102,3 +110,3 @@ next && next(); | ||
let original = res.end; | ||
function hook () { | ||
function headers_hook () { | ||
res.end = original; | ||
@@ -118,3 +126,3 @@ if (!res.headersSent) { | ||
} | ||
res.end = hook; | ||
res.end = headers_hook; | ||
@@ -130,5 +138,5 @@ next && next(); | ||
res.end = original; | ||
mung.onError(e, req, res); | ||
return mung.onError(e, req, res); | ||
}; | ||
function hook () { | ||
function headers_async_hook () { | ||
if (res.headersSent) | ||
@@ -151,3 +159,3 @@ return original.apply(this, args); | ||
} | ||
res.end = hook; | ||
res.end = headers_async_hook; | ||
@@ -154,0 +162,0 @@ next && next(); |
{ | ||
"name": "express-mung", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Transform an express response (or make until no good)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
19453
403