dddp/websocket.py
def process_ddp(self, data):
        """Process a single DDP message."""
        msg_id = data.get('id', None)
        try:
            msg = data.pop('msg')
        except KeyError:
            self.reply(
                'error', reason='Bad request',
                offendingMessage=data,
            )
            return
        try:
            # dispatch message
            self.dispatch(msg, data)
        except Exception as err:  # pylint: disable=broad-except
            # This should be the only protocol exception handler
            kwargs = {
                'msg': {'method': 'result'}.get(msg, 'error'),
            }
            if msg_id is not None:
                kwargs['id'] = msg_id
            if isinstance(err, MeteorError):
                error = err.as_dict()
            else:
                error = {
                    'error': 500,
                    'reason': 'Internal server error',
                }
            if kwargs['msg'] == 'error':
                kwargs.update(error)
            else:
                kwargs['error'] = error
            if not isinstance(err, MeteorError):
                # not a client error, should always be logged.
                stack, _ = safe_call(
                    self.logger.error, '%r %r', msg, data, exc_info=1,
                )
                if stack is not None:
                    # something went wrong while logging the error, revert to
                    # writing a stack trace to stderr.
                    traceback.print_exc(file=sys.stderr)
                    sys.stderr.write(
                        'Additionally, while handling the above error the '
                        'following error was encountered:\n'
                    )
                    sys.stderr.write(stack)
            elif settings.DEBUG:
                print('ERROR: %s' % err)
                dprint('msg', msg)
                dprint('data', data)
                error.setdefault('details', traceback.format_exc())
                # print stack trace for client errors when DEBUG is True.
                print(error['details'])
            self.reply(**kwargs)
            if msg_id and msg == 'method':
                self.reply('updated', methods=[msg_id])
def process_ddp(self, data):
        msg_id = data.get('id', None)
        try:
            msg = data.pop('msg')
        except KeyError:
            self.reply(
                'error', reason='Bad request',
                offendingMessage=data,
            )
            return
        try:
            # dispatch message
            self.dispatch(msg, data)
        except Exception as err:  # pylint: disable=broad-except
            # This should be the only protocol exception handler
            kwargs = {
                'msg': {'method': 'result'}.get(msg, 'error'),
            }
            if msg_id is not None:
                kwargs['id'] = msg_id
            if isinstance(err, MeteorError):
                error = err.as_dict()
            else:
                error = {
                    'error': 500,
                    'reason': 'Internal server error',
                }
            if kwargs['msg'] == 'error':
                kwargs.update(error)
            else:
                kwargs['error'] = error
            if not isinstance(err, MeteorError):
                # not a client error, should always be logged.
                stack, _ = safe_call(
                    self.logger.error, '%r %r', msg, data, exc_info=1,
                )
                if stack is not None:
                    # something went wrong while logging the error, revert to
                    # writing a stack trace to stderr.
                    traceback.print_exc(file=sys.stderr)
                    sys.stderr.write(
                        'Additionally, while handling the above error the '
                        'following error was encountered:\n'
                    )
                    sys.stderr.write(stack)
            elif settings.DEBUG:
                print('ERROR: %s' % err)
                dprint('msg', msg)
                dprint('data', data)
                error.setdefault('details', traceback.format_exc())
                # print stack trace for client errors when DEBUG is True.
                print(error['details'])
            self.reply(**kwargs)
            if msg_id and msg == 'method':
                self.reply('updated', methods=[msg_id])
def process_ddp ( self , data ) : msg_id = data . get ( 'id' , None ) try : msg = data . pop ( 'msg' ) except KeyError : self . reply ( 'error' , reason = 'Bad request' , offendingMessage = data , ) return try : # dispatch message self . dispatch ( msg , data ) except Exception as err : # pylint: disable=broad-except # This should be the only protocol exception handler kwargs = { 'msg' : { 'method' : 'result' } . get ( msg , 'error' ) , } if msg_id is not None : kwargs [ 'id' ] = msg_id if isinstance ( err , MeteorError ) : error = err . as_dict ( ) else : error = { 'error' : 500 , 'reason' : 'Internal server error' , } if kwargs [ 'msg' ] == 'error' : kwargs . update ( error ) else : kwargs [ 'error' ] = error if not isinstance ( err , MeteorError ) : # not a client error, should always be logged. stack , _ = safe_call ( self . logger . error , '%r %r' , msg , data , exc_info = 1 , ) if stack is not None : # something went wrong while logging the error, revert to # writing a stack trace to stderr. traceback . print_exc ( file = sys . stderr ) sys . stderr . write ( 'Additionally, while handling the above error the ' 'following error was encountered:\n' ) sys . stderr . write ( stack ) elif settings . DEBUG : print ( 'ERROR: %s' % err ) dprint ( 'msg' , msg ) dprint ( 'data' , data ) error . setdefault ( 'details' , traceback . format_exc ( ) ) # print stack trace for client errors when DEBUG is True. print ( error [ 'details' ] ) self . reply ( * * kwargs ) if msg_id and msg == 'method' : self . reply ( 'updated' , methods = [ msg_id ] )
Process a single DDP message.
Process a single DDP message .