Comparing version 8.4.0 to 8.4.1
@@ -0,1 +1,5 @@ | ||
<a name="8.4.1"></a> | ||
### 8.4.1 (2019-11-27) | ||
<a name="8.4.0"></a> | ||
@@ -2,0 +6,0 @@ ## 8.4.0 (2019-07-31) |
@@ -5,2 +5,4 @@ // Copyright 2012 Mark Cavage, Inc. All rights reserved. | ||
var errors = require('restify-errors'); | ||
///--- Exports | ||
@@ -20,3 +22,14 @@ | ||
function formatJSON(req, res, body) { | ||
var data = body ? JSON.stringify(body) : 'null'; | ||
var data = 'null'; | ||
if (body) { | ||
try { | ||
data = JSON.stringify(body); | ||
} catch (e) { | ||
throw new errors.InternalServerError( | ||
{ cause: e, info: { formatter: 'json' } }, | ||
'could not format response body' | ||
); | ||
} | ||
} | ||
// Setting the content-length header is not a formatting feature and should | ||
@@ -23,0 +36,0 @@ // be separated into another module |
@@ -497,2 +497,4 @@ // Copyright 2012 Mark Cavage, Inc. All rights reserved. | ||
var formatterType = type; | ||
if (self._charSet) { | ||
@@ -510,3 +512,22 @@ type = type + '; charset=' + self._charSet; | ||
return flush(self, formatter(self.req, self, body)); | ||
var formattedBody; | ||
try { | ||
formattedBody = formatter(self.req, self, body); | ||
} catch (e) { | ||
if ( | ||
e instanceof errors.RestError || | ||
e instanceof errors.HttpError | ||
) { | ||
var res = formatterError( | ||
self, | ||
e, | ||
'error in formatter (' + | ||
formatterType + | ||
') formatting response body' | ||
); | ||
return res; | ||
} | ||
throw e; | ||
} | ||
return flush(self, formattedBody); | ||
} | ||
@@ -878,5 +899,6 @@ } | ||
* @param {Error} err - error | ||
* @param {String} [msg] - custom log message | ||
* @returns {Response} response | ||
*/ | ||
function formatterError(res, err) { | ||
function formatterError(res, err, msg) { | ||
// If the user provided a non-success error code, we don't want to | ||
@@ -889,2 +911,6 @@ // mess with it since their error is probably more important than | ||
if (typeof msg !== 'string') { | ||
msg = 'error retrieving formatter'; | ||
} | ||
res.log.warn( | ||
@@ -895,3 +921,3 @@ { | ||
}, | ||
'error retrieving formatter' | ||
msg | ||
); | ||
@@ -898,0 +924,0 @@ |
@@ -77,3 +77,3 @@ { | ||
], | ||
"version": "8.4.0", | ||
"version": "8.4.1", | ||
"repository": { | ||
@@ -145,2 +145,3 @@ "type": "git", | ||
"rimraf": "^2.6.3", | ||
"sinon": "^7.5.0", | ||
"validator": "^7.2.0", | ||
@@ -147,0 +148,0 @@ "watershed": "^0.4.0" |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
8348
6
2138762
25
73