Skip to content

Commit 9969c8e

Browse files
committed
updated error catching
1 parent 7dc1965 commit 9969c8e

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • samples/web-app-sql-database/python/src

samples/web-app-sql-database/python/src/app.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ def read_activities_from_db(username: str | None = None) -> List[Tuple[str, str]
5252
activity_list = activities_helper.read_activities(username)
5353
for activity in activity_list:
5454
result.append((activity["id"], activity["activity"]))
55+
except (ConnectionError, ValueError, KeyError) as e:
56+
logger.error("Expected error reading activities: %s", e)
5557
except Exception as e:
56-
logger.error("Error reading activities: %s", e)
58+
logger.error("Unexpected system error reading activities: %s", e)
5759
return result
5860

5961
@app.route('/', methods=['GET', 'POST'])
@@ -88,8 +90,10 @@ def index():
8890
# Append the activity to the in-memory list
8991
activities.append((inserted_activity["id"], inserted_activity["activity"]))
9092
logger.info(f"Activity created: {inserted_activity['id']}")
93+
except (ConnectionError, ValueError) as e:
94+
logger.error("Expected error creating/updating activity: %s", e)
9195
except Exception as e:
92-
logger.error("Error creating/updating activity: %s", e)
96+
logger.error("Unexpected system error creating/updating activity: %s", e)
9397

9498
return redirect(url_for('index'))
9599

@@ -117,8 +121,10 @@ def delete(activity_id: int):
117121
logger.info(f"Activity deleted: {db_activity_id}")
118122
else:
119123
logger.warning(f"No activity found with ID: {db_activity_id}")
124+
except (ConnectionError, ValueError) as e:
125+
logger.error("Expected error deleting activity: %s", e)
120126
except Exception as e:
121-
logger.error("Error deleting activity: %s", e)
127+
logger.error("Unexpected system error deleting activity: %s", e)
122128

123129
return redirect(url_for('index'))
124130

@@ -132,7 +138,9 @@ def update(activity_id: int):
132138
# Redirect to index with edit parameters
133139
return redirect(url_for('index', edit_id=db_activity_id, edit_activity=activity_text))
134140
except (ConnectionError, ValueError) as e:
135-
logger.error("Error preparing activity for update: %s", e)
141+
logger.error("Expected error preparing activity for update: %s", e)
142+
except Exception as e:
143+
logger.error("Unexpected system error preparing activity for update: %s", e)
136144

137145
return redirect(url_for('index'))
138146

0 commit comments

Comments
 (0)