@@ -277,30 +277,36 @@ def export_session(project_name: str, session_id: str) -> FlaskReturn:
277277 return json_ok ({"error" : "Session not found" }), 404
278278
279279 fmt = request .args .get ("format" , "md" )
280- session = parse_session (filepath )
281- rules = current_app .config .get ("EXCLUSION_RULES" ) or []
282- if is_session_excluded (rules , session , project_name ):
283- return json_ok ({"error" : "Session not found" }), 404
284- stats = compute_stats (session )
285- title_slug = slugify (session ["title" ], default = "session" )
280+ try :
281+ session = parse_session (filepath )
282+ rules = current_app .config .get ("EXCLUSION_RULES" ) or []
283+ if is_session_excluded (rules , session , project_name ):
284+ return json_ok ({"error" : "Session not found" }), 404
285+ stats = compute_stats (session )
286+ title_slug = slugify (session ["title" ], default = "session" )
287+
288+ if fmt == "json" :
289+ content = session_to_json (session , stats )
290+ buf = io .BytesIO (content .encode ("utf-8" ))
291+ buf .seek (0 )
292+ return send_file (
293+ buf ,
294+ mimetype = "application/json" ,
295+ as_attachment = True ,
296+ download_name = f"{ title_slug } .json" , # type: ignore[call-arg]
297+ )
286298
287- if fmt == "json" :
288- content = session_to_json (session , stats )
289- buf = io .BytesIO (content .encode ("utf-8" ))
299+ md = session_to_markdown (session , stats )
300+ buf = io .BytesIO (md .encode ("utf-8" ))
290301 buf .seek (0 )
291302 return send_file (
292303 buf ,
293- mimetype = "application/json " ,
304+ mimetype = "text/markdown " ,
294305 as_attachment = True ,
295- download_name = f"{ title_slug } .json " , # type: ignore[call-arg]
306+ download_name = f"{ title_slug } .md " , # type: ignore[call-arg]
296307 )
297-
298- md = session_to_markdown (session , stats )
299- buf = io .BytesIO (md .encode ("utf-8" ))
300- buf .seek (0 )
301- return send_file (
302- buf ,
303- mimetype = "text/markdown" ,
304- as_attachment = True ,
305- download_name = f"{ title_slug } .md" , # type: ignore[call-arg]
306- )
308+ except Exception :
309+ current_app .logger .exception (
310+ "Failed to export session %s/%s" , project_name , session_id
311+ )
312+ return json_ok ({"error" : "Internal server error exporting session" }), 500
0 commit comments