Created
August 24, 2012 19:53
-
-
Save JesterXL/3454988 to your computer and use it in GitHub Desktop.
Shows how TO and how NOT to do Backbone Error handling.
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
/* | |
Bad | |
- Wrong function signature, no logging, no indication what went wrong, no indication where. | |
- Developers go WTF | |
- QA goes WTF | |
- PM's go WTF | |
- Firebug/Safari/Chrome tell you "404", but not on which file was asking for it, nor why. | |
*/ | |
SomeBackboneCollection.prototype.onError = function(resp) {}; | |
/* | |
Good | |
- Says what went wrong, with possible why. Indicates it's an error. Defines where: what class & what method. | |
- Developers go "not my problem, blame a server guy" | |
- QA goes "I'm going to email a server guy and not interrupt a client guy" | |
- PM's go "Client dev helped me quickly identify problem so I can resolve and look like t3h hotness. Those server guys shall feel my wrath." | |
- No moar fire drills. | |
- | |
*/ | |
SomeBackboneCollection.prototype.onError = function(jqXHR, textStatus, errorThrown) | |
{ | |
logger.error("SomeBackboneCollection::onError, Failed to retrieve the required XML file for our localized error definitions."); | |
try | |
{ | |
logger.error(textStatus.responseText); | |
} | |
catch(e){} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment