- self.dispatcher.dispatch(msg)
- #try:
- # d.dispatch(msg)
- #except dis.BadRouteError, inst:
- # sock.sendto('Bad route from : ' + inst.cmd + '\n', addr)
- #except dis.CommandNotFoundError, inst:
- # sock.sendto('Command not found : ' + inst.cmd + '\n', addr)
+ try:
+ result = self.dispatcher.dispatch(msg)
+ if result is not None:
+ result = serializer.serialize(result)
+ response = u'OK '
+ except dispatcher.Error, e:
+ result = unicode(e) + u'\n'
+ response = u'ERROR '
+ except Exception, e:
+ import traceback
+ result = u'Internal server error'
+ traceback.print_exc() # TODO logging!
+ response = u'ERROR '
+ if result is None:
+ response += u'0'
+ else:
+ response += u'%d\n%s' % (len(result), result)
+ self.file.sendto(response, addr)