浏览代码

catch input preprocess_func and valid_func 's exception

wangweimin 5 年之前
父节点
当前提交
5d446b0e19
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      pywebio/input_ctrl.py

+ 6 - 2
pywebio/input_ctrl.py

@@ -60,8 +60,12 @@ async def input_control(spec, preprocess_funcs, item_valid_funcs, form_valid_fun
 
 
 def check_item(name, data, valid_func, preprocess_func):
-    data = preprocess_func(data)
-    error_msg = valid_func(data)
+    try:
+        data = preprocess_func(data)
+        error_msg = valid_func(data)
+    except:
+        # todo log warning
+        error_msg = '字段内容不合法'
     if error_msg is not None:
         send_msg('update_input', dict(target_name=name, attributes={
             'valid_status': False,