浏览代码

no traceback expose to user when debug=False

wangweimin 2 年之前
父节点
当前提交
5242db7b6b
共有 1 个文件被更改,包括 7 次插入8 次删除
  1. 7 8
      pywebio/session/base.py

+ 7 - 8
pywebio/session/base.py

@@ -134,20 +134,19 @@ class Session:
         from . import run_js
         from . import run_js
         from . import info as session_info
         from . import info as session_info
 
 
-        logger.exception('Error')
-
-        toast_msg = "应用发生内部错误" if 'zh' in session_info.user_language else "An internal error occurred in the application"
-
-        e_type, e_value, e_tb = sys.exc_info()
-        lines = traceback.format_exception(e_type, e_value, e_tb)
-        traceback_msg = ''.join(lines)
+        # log exception in server
+        logger.exception('Unhandled error in pywebio app')
 
 
         try:
         try:
+            toast_msg = "应用发生内部错误" if 'zh' in session_info.user_language else "An internal error occurred in the application"
             if type(self).debug:
             if type(self).debug:
+                e_type, e_value, e_tb = sys.exc_info()
+                lines = traceback.format_exception(e_type, e_value, e_tb)
+                traceback_msg = ''.join(lines)
                 popup(title=toast_msg, content=put_error(traceback_msg), size=PopupSize.LARGE)
                 popup(title=toast_msg, content=put_error(traceback_msg), size=PopupSize.LARGE)
+                run_js("console.error(traceback_msg)", traceback_msg='Internal Server Error\n' + traceback_msg)
             else:
             else:
                 toast(toast_msg, duration=1, color='error')
                 toast(toast_msg, duration=1, color='error')
-                run_js("console.error(traceback_msg)", traceback_msg='Internal Server Error\n' + traceback_msg)
         except Exception:
         except Exception:
             pass
             pass