mbosse99 commited on
Commit
248b986
·
1 Parent(s): af8ae64

Added try catch for db update

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -109,20 +109,24 @@ def change_question_type():
109
  st.session_state["question_type"] = "question"
110
 
111
  def update_questions_and_tasks():
112
- with st.spinner("Updating questions and tasks..."):
113
- client: CosmosClient = st.session_state["db"]
114
- database = client.get_database_client("assessment-database")
115
- container = database.get_container_client("assessments")
116
- assessment = st.session_state["assessment_db_object"]
117
- questions_for_db = []
118
- for question in st.session_state["questions_for_interview"]:
119
- questions_for_db.append({"question": question["question"], "perfect_answer": question["perfect_answer"], "score": "", "evaluation": ""})
120
- assessment["questions"] = questions_for_db
121
- tasks_for_db = []
122
- for task in st.session_state["tasks_for_interview"]:
123
- tasks_for_db.append({"coding_task": task["task"], "perfect_solution": task["perfect_solution"], "score": "", "evaluation": ""})
124
- assessment["coding_tasks"] = tasks_for_db
125
- container.upsert_item(assessment)
 
 
 
 
126
 
127
  if "topics" not in st.session_state:
128
  topics = list(set([topic["dimension"] for topic in get_question_topics() if topic["dimension"] != None]))
 
109
  st.session_state["question_type"] = "question"
110
 
111
  def update_questions_and_tasks():
112
+ try:
113
+ with st.spinner("Updating questions and tasks..."):
114
+ client: CosmosClient = st.session_state["db"]
115
+ database = client.get_database_client("assessment-database")
116
+ container = database.get_container_client("assessments")
117
+ assessment = st.session_state["assessment_db_object"]
118
+ questions_for_db = []
119
+ for question in st.session_state["questions_for_interview"]:
120
+ questions_for_db.append({"question": question["question"], "perfect_answer": question["perfect_answer"], "score": "", "evaluation": ""})
121
+ assessment["questions"] = questions_for_db
122
+ tasks_for_db = []
123
+ for task in st.session_state["tasks_for_interview"]:
124
+ tasks_for_db.append({"coding_task": task["task"], "perfect_solution": task["perfect_solution"], "score": "", "evaluation": ""})
125
+ assessment["coding_tasks"] = tasks_for_db
126
+ container.upsert_item(assessment)
127
+ except Exception as e:
128
+ print(f"Fehler beim Speichern der Fragen und Aufgaben: {e}")
129
+ st.error("Someting went wrong. Please try again later.", icon="🚨")
130
 
131
  if "topics" not in st.session_state:
132
  topics = list(set([topic["dimension"] for topic in get_question_topics() if topic["dimension"] != None]))