Last active
November 4, 2016 23:19
-
-
Save alexindigo/e9655d78e6f2d4aeef1980304f594e99 to your computer and use it in GitHub Desktop.
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
callbackMethod(input, function myHandler(error, result) { | |
if (error) | |
{ | |
// check for error, since it's in my face here as first argument | |
return; | |
} | |
// do other things | |
}); | |
// vs | |
promiseMethod(input).then(function halfOfMyHandler(result) { | |
// looks like I forgot to check for errors at all | |
// just do things | |
}); | |
// vs | |
promiseMethod(input).then(function halfOfMyHandler(result) { | |
// just do things | |
}).catch(function anotherHalfOfMyHandler(error) { | |
// so why do I need to write two functions? o_0 | |
}); | |
In real life app, you'd have more than one result handler and more than one error handler, and it will be more cognitive load try to keep track if you used proper error handler for the given result handler.
I personally, not a fan of separating error handling from "business logic", since it's not pure business logic at this level (where your code touches some kind of I/O) and usually you'd keep your "true business logic" in a separate module.
var myLogic = require('./lib/my_logic.js');
callbackMethod(input, function myHandler(error, result) {
if (error)
{
// check for error, since it's in my face here as first argument
return;
}
myLogic.doThings(result.data);
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From: http://paste.ubuntu.com/23427957/