Simple one line native Promise logging

// Usage import applyPromiseLog from '../utils/applyPromiseLog'; applyPromiseLog(Promise); connectMongoose(process.env.MONGODB_URI) .log() .then(() => { listener(server).log(); }); // Definition export default function applyPromiseLog(promise = Promise) { // Sicne we are reassigning prototype to Promise, we disable the linting /* eslint-disable no-param-reassign */ promise.prototype.log = function log() { return this .then(message => { // Or use your own logging tools console.log(message); return message; }) .catch(error => { // Or use your own logging tools console.error(error); return promise.reject(error); }); }; }
A simple `.log()` empower your debugging ability and readability.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.