Last active
August 28, 2017 09:10
-
-
Save Tiriel/95278e427d7317224b304231f84eee31 to your computer and use it in GitHub Desktop.
NodeJS utilities (outgoing requests interceptor, unhandledRejection monitor)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use-strict'; | |
/** | |
* Debug toolbox startng point | |
* Usage : | |
* const utilities = require('path-to-utilities.js'); | |
* utilities.requestLogger(require('http')); | |
* utilities.unhandledRejectionMonitor(); | |
*/ | |
module.exports.requestLogger = function(httpModule){ | |
let original = httpModule.request; | |
httpModule.request = function(options, callback){ | |
console.log('----- Request :----'); | |
console.log('-- URL : '+options.href||'URL : '+options.proto+"://"+options.host+options.path); | |
console.log('-- Method : '+options.method); | |
console.log('-- Headers : '+options.headers); | |
console.log('-- Body : '+options.body); | |
console.log('-------------------'); | |
return original(options, callback) | |
} | |
} | |
module.exports.unhandledRejectionsMonitor = function () { | |
process.on('unhandledRejection', (reason, p) => { | |
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); | |
console.log('----- UnhandledRejection :----'); | |
console.log('-- Object : ' + p); | |
console.log('-- Reason : ' + reason); | |
console.log('-- source : ' + reason.fileName + ' - ' + reason.lineNumber); | |
console.log('------------------------------'); | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment