Created
March 10, 2012 08:06
-
-
Save ayoung/2010792 to your computer and use it in GitHub Desktop.
Api Errors
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 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