Merge pull request #43 from strongloop/update/deps

Upgrade dependencies to their latest versions
This commit is contained in:
Miroslav Bajtoš 2017-02-01 09:49:47 +01:00 committed by GitHub
commit 4dddf78354
4 changed files with 32 additions and 20 deletions

View File

@ -19,9 +19,10 @@ module.exports = negotiateContentProducer;
*
* @param req request object
* @param {Object} options options of strong-error-handler
* @param {Function} logWarning a logger function for reporting warnings
* @returns {Function} Opeartion function with signature `fn(res, data)`
*/
function negotiateContentProducer(req, options) {
function negotiateContentProducer(req, logWarning, options) {
var SUPPORTED_TYPES = [
'application/json', 'json',
'text/html', 'html',
@ -66,8 +67,7 @@ function negotiateContentProducer(req, options) {
// format passed through query but not supported
var msg = util.format('Response _format "%s" is not supported' +
'used "%s" instead"', query._format, defaultType);
res.header('X-Warning', msg);
debug(msg);
logWarning(msg);
}
}

View File

@ -51,7 +51,12 @@ exports = module.exports = function createStrongErrorHandler(options) {
res.setHeader('X-Content-Type-Options', 'nosniff');
res.statusCode = data.statusCode;
var sendResponse = negotiateContentProducer(req, options);
var sendResponse = negotiateContentProducer(req, warn, options);
sendResponse(res, data);
function warn(msg) {
res.header('X-Warning', msg);
debug(msg);
}
};
};

View File

@ -20,17 +20,17 @@
"accepts": "^1.3.3",
"debug": "^2.2.0",
"ejs": "^2.4.2",
"http-status": "^0.2.2",
"http-status": "^1.0.0",
"js2xmlparser": "^2.0.2",
"strong-globalize": "^2.6.7"
},
"devDependencies": {
"chai": "^2.1.1",
"eslint": "^2.13.1",
"eslint-config-loopback": "^4.0.0",
"chai": "^3.5.0",
"eslint": "^3.14.1",
"eslint-config-loopback": "^8.0.0",
"express": "^4.13.4",
"mocha": "^2.1.0",
"supertest": "^1.1.0"
"mocha": "^3.2.0",
"supertest": "^3.0.0"
},
"browser": {
"strong-error-handler": false

View File

@ -625,6 +625,12 @@ describe('strong-error-handler', function() {
.set('Accept', 'application/json')
.expect('Content-Type', /^text\/html/, done);
});
it('handles unknown _format query', function() {
givenErrorHandlerForError();
return request.get('/?_format=unknown')
.expect('X-Warning', /_format.*not supported/);
});
});
it('does not modify "options" argument', function(done) {
@ -672,7 +678,18 @@ function setupHttpServerAndClient(done) {
res.end(msg);
return;
}
_requestHandler(req, res, warnUnhandledError);
function warnUnhandledError(err) {
console.log('unexpected: strong-error-handler called next with',
(err && (err.stack || err)) || 'no error');
res.statusCode = 500;
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
res.end(err ?
'Unhandled strong-error-handler error:\n' + (err.stack || err) :
'The error was silently discared by strong-error-handler');
}
});
app.listen(0, function() {
@ -687,16 +704,6 @@ function setupHttpServerAndClient(done) {
});
}
function warnUnhandledError(err) {
console.log('unexpected: strong-error-handler called next with '
(err && (err.stack || err)) || 'no error');
res.statusCode = 500;
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
res.end(err ?
'Unhandled strong-error-handler error:\n' + (err.stack || err) :
'The error was silently discared by strong-error-handler');
}
function ErrorWithProps(props) {
this.name = props.name || 'ErrorWithProps';
for (var p in props) {