Merge pull request #43 from strongloop/update/deps
Upgrade dependencies to their latest versions
This commit is contained in:
commit
4dddf78354
|
@ -19,9 +19,10 @@ module.exports = negotiateContentProducer;
|
||||||
*
|
*
|
||||||
* @param req request object
|
* @param req request object
|
||||||
* @param {Object} options options of strong-error-handler
|
* @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)`
|
* @returns {Function} Opeartion function with signature `fn(res, data)`
|
||||||
*/
|
*/
|
||||||
function negotiateContentProducer(req, options) {
|
function negotiateContentProducer(req, logWarning, options) {
|
||||||
var SUPPORTED_TYPES = [
|
var SUPPORTED_TYPES = [
|
||||||
'application/json', 'json',
|
'application/json', 'json',
|
||||||
'text/html', 'html',
|
'text/html', 'html',
|
||||||
|
@ -66,8 +67,7 @@ function negotiateContentProducer(req, options) {
|
||||||
// format passed through query but not supported
|
// format passed through query but not supported
|
||||||
var msg = util.format('Response _format "%s" is not supported' +
|
var msg = util.format('Response _format "%s" is not supported' +
|
||||||
'used "%s" instead"', query._format, defaultType);
|
'used "%s" instead"', query._format, defaultType);
|
||||||
res.header('X-Warning', msg);
|
logWarning(msg);
|
||||||
debug(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,12 @@ exports = module.exports = function createStrongErrorHandler(options) {
|
||||||
res.setHeader('X-Content-Type-Options', 'nosniff');
|
res.setHeader('X-Content-Type-Options', 'nosniff');
|
||||||
res.statusCode = data.statusCode;
|
res.statusCode = data.statusCode;
|
||||||
|
|
||||||
var sendResponse = negotiateContentProducer(req, options);
|
var sendResponse = negotiateContentProducer(req, warn, options);
|
||||||
sendResponse(res, data);
|
sendResponse(res, data);
|
||||||
|
|
||||||
|
function warn(msg) {
|
||||||
|
res.header('X-Warning', msg);
|
||||||
|
debug(msg);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
12
package.json
12
package.json
|
@ -20,17 +20,17 @@
|
||||||
"accepts": "^1.3.3",
|
"accepts": "^1.3.3",
|
||||||
"debug": "^2.2.0",
|
"debug": "^2.2.0",
|
||||||
"ejs": "^2.4.2",
|
"ejs": "^2.4.2",
|
||||||
"http-status": "^0.2.2",
|
"http-status": "^1.0.0",
|
||||||
"js2xmlparser": "^2.0.2",
|
"js2xmlparser": "^2.0.2",
|
||||||
"strong-globalize": "^2.6.7"
|
"strong-globalize": "^2.6.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^2.1.1",
|
"chai": "^3.5.0",
|
||||||
"eslint": "^2.13.1",
|
"eslint": "^3.14.1",
|
||||||
"eslint-config-loopback": "^4.0.0",
|
"eslint-config-loopback": "^8.0.0",
|
||||||
"express": "^4.13.4",
|
"express": "^4.13.4",
|
||||||
"mocha": "^2.1.0",
|
"mocha": "^3.2.0",
|
||||||
"supertest": "^1.1.0"
|
"supertest": "^3.0.0"
|
||||||
},
|
},
|
||||||
"browser": {
|
"browser": {
|
||||||
"strong-error-handler": false
|
"strong-error-handler": false
|
||||||
|
|
|
@ -625,6 +625,12 @@ describe('strong-error-handler', function() {
|
||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json')
|
||||||
.expect('Content-Type', /^text\/html/, done);
|
.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) {
|
it('does not modify "options" argument', function(done) {
|
||||||
|
@ -672,7 +678,18 @@ function setupHttpServerAndClient(done) {
|
||||||
res.end(msg);
|
res.end(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_requestHandler(req, res, warnUnhandledError);
|
_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() {
|
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) {
|
function ErrorWithProps(props) {
|
||||||
this.name = props.name || 'ErrorWithProps';
|
this.name = props.name || 'ErrorWithProps';
|
||||||
for (var p in props) {
|
for (var p in props) {
|
||||||
|
|
Loading…
Reference in New Issue