2016-05-11 11:53:28 +00:00
|
|
|
// Copyright IBM Corp. 2016. All Rights Reserved.
|
|
|
|
// Node module: strong-error-handler
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var format = require('util').format;
|
2016-08-17 20:51:32 +00:00
|
|
|
var g = require('strong-globalize')();
|
2016-05-11 11:53:28 +00:00
|
|
|
|
|
|
|
module.exports = function logToConsole(req, err) {
|
|
|
|
if (!Array.isArray(err)) {
|
2016-08-17 20:51:32 +00:00
|
|
|
g.error('Unhandled error for request %s %s: %s',
|
2016-05-11 11:53:28 +00:00
|
|
|
req.method, req.url, err.stack || err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-17 20:51:32 +00:00
|
|
|
var errMsg = g.f('Unhandled array of errors for request %s %s\n',
|
|
|
|
req.method, req.url);
|
2016-05-11 11:53:28 +00:00
|
|
|
var errors = err.map(formatError).join('\n');
|
2016-08-17 20:51:32 +00:00
|
|
|
console.error(errMsg, errors);
|
2016-05-11 11:53:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function formatError(err) {
|
|
|
|
return format('%s', err.stack || err);
|
|
|
|
}
|