Skip to content

Instantly share code, notes, and snippets.

@luhn
Last active December 18, 2015 17:19
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 luhn/5818011 to your computer and use it in GitHub Desktop.
Save luhn/5818011 to your computer and use it in GitHub Desktop.
from twisted.python.failure import Failure
from autobahn.wamp import WampServerProtocol
class WampException(Exception):
"""A base class for an application exception. Can be subclass and
define a unique msg."""
msg = None
def __init__(self, *args):
if len(args) == 0:
args = ( self.msg, )
Exception.__init__(self, *args)
class Protocol(WampServerProtocol):
def onSessionOpen(self):
self.includeTraceback = False # Don't send tracebacks to client
def onAfterCallError(self, error, call):
"""Handle any exceptions raised. Any exception that is not a subclass
of WampException will be replaced with a very generic exception."""
if error.check(WampException):
return error
# Print out traceback and send only a generic error to client.
error.printTraceback()
return Failure(Exception('An unexpected error has occurred.'),
Exception)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment