Skip to content

Commit

Permalink
Merge pull request #29 from avantifellows/display_error
Browse files Browse the repository at this point in the history
displays meaningful instruction instead of 500 internal server error
  • Loading branch information
suryabulusu authored Jul 17, 2023
2 parents 55f6721 + e850bbe commit f68d43e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/routers/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,22 @@ def student_quiz_report(request: Request, session_id: str, user_id: str):
)
except KeyError:
raise HTTPException(
status_code=400, detail="No student_quiz_report found"
status_code=400, detail="No student_quiz_report found. Unknown error occurred."
)

if len(data) == 0:
# no data
error_data = {
"session_id": session_id,
"user_id": user_id,
"error_message": "No report found. Please contact admin.",
"status_code": 404
}
return self._templates.TemplateResponse(
"error.html",
{"request": request, "error_data": error_data}
)

report_data = {}
report_data["student_name"] = ""
test_id = data[0]["test_id"]
Expand Down
13 changes: 13 additions & 0 deletions app/templates/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "layout.html" %}
{% block title %}Error{% endblock %}

{% block content %}

<section id="error_page">
<div id="section_heading">{{ error_data["error_message"] }}</div>
<div id="name_card">
<p>Student ID: {{error_data["user_id"]}}
</div>
</section>

{% endblock %}

0 comments on commit f68d43e

Please sign in to comment.