Skip to content

Commit

Permalink
fix: handle undefined rejections
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-abrioux authored and wbt committed Dec 10, 2021
1 parent 4572c2a commit 2299d19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/winston/rejection-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ module.exports = class RejectionHandler {
* @returns {mixed} - TODO: add return description.
*/
getAllInfo(err) {
let { message } = err;
if (!message && typeof err === 'string') {
message = err;
let message = null;
if (err) {
message = typeof err === 'string' ? err : err.message;
}

return {
Expand All @@ -85,9 +85,9 @@ module.exports = class RejectionHandler {
level: 'error',
message: [
`unhandledRejection: ${message || '(no error message)'}`,
err.stack || ' No stack trace'
err && err.stack || ' No stack trace'
].join('\n'),
stack: err.stack,
stack: err && err.stack,
exception: true,
date: new Date().toString(),
process: this.getProcessInfo(),
Expand Down
6 changes: 6 additions & 0 deletions test/rejection-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ describe('UnhandledRejectionHandler', function () {
helpers.reject('wtf this rejection').then(done());
});

it('.getAllInfo(undefined)', function () {
var handler = helpers.rejectionHandler();
// eslint-disable-next-line no-undefined
handler.getAllInfo(undefined);
});

after(function () {
//
// Restore normal `runTest` functionality
Expand Down

0 comments on commit 2299d19

Please sign in to comment.