Skip to content

Instantly share code, notes, and snippets.

@russellhaering
Created July 21, 2011 22:32
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 russellhaering/1098395 to your computer and use it in GitHub Desktop.
Save russellhaering/1098395 to your computer and use it in GitHub Desktop.
Node.js Thrift Server Exception Handling
/** This is what a thrift service implementation in Node.js _currently_ looks like */
var CURRENT_HANDLER = {
// On success, the return argument is passed as the only argument to the callback
HelloWorld: function(name, callback) {
callback("hello " + name);
},
// When something goes wrong, there is no way to get the exception back to the client
UhOhWorld: function(name, callback) {
var e = new ttypes.UhOhException("I can't do that " + name);
}
};
/** This is what a "node-like" thrift service implementation _should_ look like */
var CANONICAL_HANDLER = {
// On success, the return argument is passed as the second argument to the callback
HelloWorld: function(name, callback) {
callback(null, "hello " + name);
},
// On error, the exception is passed as the first argument to the callback
UhOhWorld: function(name, callback) {
callback(new ttypes.UhOhException("I can't do that " + name));
}
};
@cypres
Copy link

cypres commented Aug 25, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment