Javascript Error handler
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
var fs = require('fs') | |
fs.readFile('app.js', errorHandler(function (content) { | |
console.log('File contents are ' + content) | |
}) | |
) | |
function errorHandler(callback) { | |
return function (err, result) { | |
if (err) { | |
// here goes the common logic for handling of the error | |
// add it according to strategy for handling the error | |
console.error("Error occurred: " + err) | |
} else { | |
callback(result) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment