Last active
December 18, 2015 17:19
-
-
Save luhn/5818011 to your computer and use it in GitHub Desktop.
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
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