Created
July 21, 2011 22:32
-
-
Save russellhaering/1098395 to your computer and use it in GitHub Desktop.
Node.js Thrift Server Exception Handling
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
/** 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)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussed in https://issues.apache.org/jira/browse/THRIFT-1267