Browse Source

catch input preprocess_func and valid_func 's exception

wangweimin 5 năm trước cách đây
mục cha
commit
5d446b0e19
1 tập tin đã thay đổi với 6 bổ sung2 xóa
  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,