Skip to content

Instantly share code, notes, and snippets.

@ayoung
Created March 10, 2012 08:06
Show Gist options
  • Save ayoung/2010792 to your computer and use it in GitHub Desktop.
Save ayoung/2010792 to your computer and use it in GitHub Desktop.
Api Errors
var errorTypes = new Hasshu({
'internal_error': 'An internal error occured',
'some_validation_error': 'Something didn\'t validate'
});
errorTypes.forEach(function(code, message) {
var errorType = // use mapper on key
exports[errorType] = function(details) {
Object.defineProperty(this, 'code', {
value: code,
enumerable: true
});
Object.defineProperty(this, 'message', {
value: message,
enumerable: true
});
if (!details)
return;
Object.defineProperty(this, 'details', {
value: details,
enumerable: true
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment