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';
|
|
|
|
|
2019-10-11 13:57:15 +00:00
|
|
|
const format = require('util').format;
|
|
|
|
const g = require('strong-globalize')();
|
2016-05-11 11:53:28 +00:00
|
|
|
|
|
|
|
module.exports = function logToConsole(req, err) {
|
|
|
|
if (!Array.isArray(err)) {
|
2020-10-12 07:56:56 +00:00
|
|
|
g.error('Request %s %s failed: %s',
|
2016-05-11 11:53:28 +00:00
|
|
|
req.method, req.url, err.stack || err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-12 07:56:56 +00:00
|
|
|
const errMsg = g.f('Request %s %s failed with multiple errors:\n',
|
2016-08-17 20:51:32 +00:00
|
|
|
req.method, req.url);
|
2019-10-11 13:57:15 +00:00
|
|
|
const 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);
|
|
|
|
}
|