Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Removes all usage of str(e) in courses endpoint #126

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions backend/project/endpoints/courses/courses_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
load_dotenv()
API_URL = getenv("API_HOST")
RESPONSE_URL = urljoin(API_URL + "/", "courses")

BASE_DB_ERROR = "Database error occurred while"
def execute_query_abort_if_db_error(query, url, query_all=False):
"""
Execute the given SQLAlchemy query and handle any SQLAlchemyError that might occur.
Expand All @@ -35,8 +35,8 @@ def execute_query_abort_if_db_error(query, url, query_all=False):
result = query.all()
else:
result = query.first()
except SQLAlchemyError as e:
response = json_message(str(e))
except SQLAlchemyError:
response = json_message(f"{BASE_DB_ERROR} executing query")
response["url"] = url
abort(500, description=response)
return result
Expand All @@ -52,9 +52,9 @@ def add_abort_if_error(to_add, url):
"""
try:
db.session.add(to_add)
except SQLAlchemyError as e:
except SQLAlchemyError:
db.session.rollback()
response = json_message(str(e))
response = json_message(f"{BASE_DB_ERROR} adding object")
response["url"] = url
abort(500, description=response)

Expand All @@ -69,9 +69,9 @@ def delete_abort_if_error(to_delete, url):
"""
try:
db.session.delete(to_delete)
except SQLAlchemyError as e:
except SQLAlchemyError:
db.session.rollback()
response = json_message(str(e))
response = json_message(f"{BASE_DB_ERROR} deleting object")
response["url"] = url
abort(500, description=response)

Expand All @@ -82,9 +82,9 @@ def commit_abort_if_error(url):
"""
try:
db.session.commit()
except SQLAlchemyError as e:
except SQLAlchemyError:
db.session.rollback()
response = json_message(str(e))
response = json_message(f"{BASE_DB_ERROR} committing changes")
response["url"] = url
abort(500, description=response)

Expand Down
Loading