@@ -70,24 +70,29 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: #
7070CONFIG_PATH = "dash_config.json"
7171
7272
73- def save_config (config ):
74- with open (CONFIG_PATH , "w" ) as f :
75- json .dump (config , f )
73+ # Internal config helpers (local to this file)
74+ _CONFIG_PATH = "dash_config.json"
7675
76+ def _save_config (config ):
77+ with open (_CONFIG_PATH , "w" ) as f :
78+ json .dump (config , f )
7779
78- def load_config ():
79- if os .path .exists (CONFIG_PATH ):
80- with open (CONFIG_PATH , "r" ) as f :
81- return json .load (f )
80+ def _load_config ():
81+ try :
82+ if os .path .exists (_CONFIG_PATH ):
83+ with open (_CONFIG_PATH , "r" ) as f :
84+ return json .load (f )
85+ except Exception :
86+ pass # ignore errors
8287 return {}
8388
8489
8590class FastAPIDashServer (BaseDashServer ):
8691 def __init__ (self , server : FastAPI ):
87- self . config = {}
92+ _save_config ({ "debug" : False }) # ensure config file exists
8893 self .server_type = "fastapi"
8994 self .server : FastAPI = server
90- self .error_handling_mode = "prune "
95+ self .error_handling_mode = "ignore "
9196 self .request_adapter = FastAPIRequestAdapter
9297 super ().__init__ ()
9398
@@ -120,7 +125,7 @@ def register_assets_blueprint(
120125 pass
121126
122127 def register_error_handlers (self ):
123- self .error_handling_mode = "prune "
128+ self .error_handling_mode = "ignore "
124129
125130 def _get_traceback (self , _secret , error : Exception ):
126131 tb = error .__traceback__
@@ -256,7 +261,7 @@ def setup_catchall(self, dash_app: Dash):
256261 @self .server .on_event ("startup" )
257262 def _setup_catchall ():
258263 dash_app .enable_dev_tools (
259- ** load_config (), first_run = False
264+ ** _load_config (), first_run = False
260265 ) # do this to make sure dev tools are enabled
261266
262267 async def catchall (request : Request ):
@@ -298,12 +303,12 @@ def after_request(self, func: Callable[[], Any] | None):
298303 def run (self , dash_app : Dash , host , port , debug , ** kwargs ):
299304 frame = inspect .stack ()[2 ]
300305 config = dict (
301- {"debug" : debug } if debug else {},
306+ {"debug" : debug } if debug else {"debug" : False },
302307 ** {
303308 f"dev_tools_{ k } " : v for k , v in dash_app ._dev_tools .items ()
304309 }, # pylint: disable=protected-access
305310 )
306- save_config (config )
311+ _save_config (config )
307312 if debug :
308313 if kwargs .get ("reload" ) is None :
309314 kwargs ["reload" ] = True
@@ -352,7 +357,7 @@ async def middleware(request, call_next):
352357 return Response (content = tb , media_type = "text/html" , status_code = 500 )
353358 return JSONResponse (
354359 status_code = 500 ,
355- content = {"error" : "InternalServerError" , "message" : str ( e . args [ 0 ]) },
360+ content = {"error" : "InternalServerError" , "message" : "An internal server error occurred." },
356361 )
357362
358363 return middleware
0 commit comments