txamqp raise error in txthrift

Asked by DarkAnthey

Hello,

How can I raise error in server with txthrift.
I have thrift shema.

exception InvalidOperation {
  1: string what,
  2: string why
}
...

And some function to raise exception for example:
if time > 60:
    raise InvalidOperation(what='Error', why='Time Error')
or
    return defer.fail(InvalidOperation(what='Error', why='Time Error'))
or
    return InvalidOperation(what='Error', why='Time Error')

But none of them is not working as expected. The server has not transferred any exception to client.

Question information

Language:
English Edit question
Status:
Answered
For:
txAMQP Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Terry Jones (terrycojones) said :
#1

Hi

Did you list the exception in the "throws" section of the service's Thrift definition? Just raising the exception should be enough if so.

BTW, Esteve Fernandez (the author of txAMQP) is on holidays until the end of August. I can try to help you in the meantime, but we may end up having to wait for him.

Terry

Revision history for this message
Matteo Brancaleoni (mbrancaleoni) said :
#2

I do in this way (example code, not really working)

class MyHandler(object)

        @defer.inlineCallbacks
        def _worker(self):
           try:
               res = yield do_some_other_work_which_returns_a_deferred
           except Exception, e:
              raise Exception("cannot do anything")

        defer.returnValue(res)

        def thrift_method(self):
            try:
                return self._worker()
            except Exception, e:
                return defer.fail(InvalidOperation(what=logid, why=e.message))

hope that can help. remind to add throws(1: InvalidOperation, ouch) to your service definition....

Can you help with this problem?

Provide an answer of your own, or ask DarkAnthey for more information if necessary.

To post a message you must log in.