Last active
December 21, 2015 07:09
-
-
Save riston/6269186 to your computer and use it in GitHub Desktop.
Callback with mutable error message.
This file contains hidden or 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
var fs = require('fs'); | |
var errorHandler = function(err, result) { | |
return function(customMessage) { | |
if (err) return err; | |
else { | |
// Call some other sync function but with my message | |
console.log(customMessage); | |
handleResult(result); | |
} | |
} | |
}; | |
fs.readFile('readme.md', 'utf-8', errorHandler()('hahahhah this does not work as this requires extra wrapper')); | |
fs.readFile('other.md', 'utf-8', errorHandler()('Actually the main point is to reuse code')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you want something more like