Skip to content

Instantly share code, notes, and snippets.

@ajduke
Created April 10, 2015 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajduke/443fb5a4d586c54014eb to your computer and use it in GitHub Desktop.
Save ajduke/443fb5a4d586c54014eb to your computer and use it in GitHub Desktop.
Javascript Error handler
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