Beispiel #1
0
def base_error_handler(ex, req, resp, params):
    """Error handler for BaseException"""
    if resp is None:
        return
    resp.body = encode.encode({
        'status': 1,
        'msg': 'Uncaught exception: ' + str(ex),
        'exception': traceback.format_exception(None, # <- type(e) by docs, but ignored
                                                ex, ex.__traceback__)
    })
Beispiel #2
0
    def on_post(self, req, res):
        """Handle POST method"""

        msg = encode.decode_from_request(req)
        if msg is None:
            raise ValueError('msg cannot be empty')

        msg_name = msg.get('name')
        msg_args = msg.get('args', dict())

        app.trigger_manager.fire(msg_name, msg_args)

        result = {'status': 0, 'message': msg_name}
        res.body = encode.encode(result)
Beispiel #3
0
    def on_post(self, req, res):
        """Handle POST method"""
        res.set_header('Access-Control-Allow-Origin', '*')
        res.set_header("Access-Control-Expose-Headers",
                       "Access-Control-Allow-Origin")
        res.set_header('Access-Control-Allow-Headers',
                       'Origin, X-Requested-With, Content-Type, Accept')

        msg = encode.decode_from_request(req)
        if msg is None:
            raise ValueError('msg cannot be empty')

        msg_name = msg.get('name')
        msg_args = msg.get('args', dict())

        try:
            result = app.trigger_manager.fire(msg_name, msg_args)
            result = {'status': 0, 'msg': result}
        except Exception as ex:
            result = {'status': 1, 'msg': type(ex).__name__ + ': ' + str(ex)}

        res.body = encode.encode(result)
Beispiel #4
0
def http_error_handler(ex, req, resp, params):
    """Error handler for HTTPError"""
    resp.body = encode.encode({
        'status': 1,
        'msg': 'HTTP error: ' + ex.status
    })
Beispiel #5
0
def value_error_handler(ex, req, resp, params):
    """Error handler for ValueError"""
    resp.body = encode.encode({
        'status': 1,
        'msg': 'Bad Request: ' + str(ex)
    })
Beispiel #6
0
 def on_get(self, req, res):
     """Handle GET method"""
     result = {'status': 0, 'msg': 'Hello'}
     res.body = encode.encode(result)