Skip to content

fix: Incorrect 500 response for invalid requests #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Changes from all 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
14 changes: 8 additions & 6 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ def get_db():
db = SessionLocal()
try:
yield db
except Exception as e:
print(f"An error occurred while accessing the database: {e}")
finally:
db.close()

Expand All @@ -93,13 +91,17 @@ def get_term_number(db, year: int, term: str) -> int:
courses = db.query(Course).filter(Course.year == year).all()

if not courses:
raise Exception(f"No courses found for year: {year}")
raise HTTPException(
status_code=404, detail=f"No courses found for year: {year}"
)

for course in courses:
if course.term_descr == term:
return course.term

raise Exception(f"Invalid term: {term} for year: {year}")
raise HTTPException(
status_code=404, detail=f"Invalid term: {term} for year: {year}"
)


def meeting_date_convert(raw_date: str) -> dict[str]:
Expand Down Expand Up @@ -342,11 +344,11 @@ def get_course(course_cid: str, db: Session = Depends(get_db)):
"""
course = db.query(Course).filter(Course.id == course_cid).first()

course_id = course.course_id

if not course:
raise HTTPException(status_code=404, detail="Course not found")

course_id = course.course_id

course_details = (
db.query(CourseDetail).filter(CourseDetail.course_id == course_id).first()
)
Expand Down