Created
August 17, 2011 15:29
-
-
Save cypres/1151782 to your computer and use it in GitHub Desktop.
node.js thrift exception test
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 thrift = require('thrift'); | |
var test = require('./gen-nodejs/test.js'), | |
ttypes = require('./gen-nodejs/test_types'); | |
var connection = thrift.createConnection('localhost', 9090), | |
client = thrift.createClient(test, connection); | |
connection.on('error', function(err) { | |
console.error(err); | |
}); | |
connection.on('connect',function () { | |
runtest(1,function() { | |
runtest(2,function() { | |
runtest(3,function() { | |
connection.end(); | |
}); | |
}); | |
}); | |
}); | |
function runtest(int, cb) | |
{ | |
console.log('Test '+int); | |
client.foo(int,function(err,response) { | |
if (err) { | |
console.log('Exception:'); | |
console.info(err); | |
cb(); | |
} else { | |
console.log('Reply:'); | |
console.info(response); | |
cb(); | |
} | |
}); | |
} |
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 thrift = require('thrift'); | |
var test = require('./gen-nodejs/test.js'), | |
ttypes = require('./gen-nodejs/test_types'); | |
var server = thrift.createServer(test, { | |
foo: function(bar,response) { | |
console.log('Got: '+bar); | |
if (bar == 1) { | |
console.log('throw MyException'); | |
response(new ttypes.MyException({code: 0x0211, message: 'Test exception'})); | |
} else if (bar == 2) { | |
console.log('throw MyOtherException'); | |
response(new ttypes.MyOtherException({message: 'Test exception'})); | |
} else { | |
console.log('okay'); | |
response(null, 1234); | |
} | |
} | |
}); | |
server.listen(9090); |
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
exception MyException { | |
1: required string message, | |
2: optional list<string> variables, | |
3: optional i16 code | |
} | |
exception MyOtherException { | |
1: required string message, | |
2: optional list<string> variables | |
} | |
service test | |
{ | |
i32 foo(1:i32 bar) throws (1:MyException me, 2:MyOtherException moe) | |
} |
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