Skip to content
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

displays meaningful instruction instead of 500 internal server error #29

Merged
merged 8 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
17 changes: 17 additions & 0 deletions app/routers/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def student_quiz_report(request: Request, session_id: str, user_id: str):
# it's possible that the strings are URL encoded.
session_id = unquote(session_id)
user_id = unquote(user_id)
data = self.__student_quiz_reports_controller.get_student_quiz_report(
suryabulusu marked this conversation as resolved.
Show resolved Hide resolved
session_id=session_id, user_id=user_id
)
try:
data = self.__student_quiz_reports_controller.get_student_quiz_report(
session_id=session_id, user_id=user_id
Expand All @@ -130,6 +133,20 @@ def student_quiz_report(request: Request, session_id: str, user_id: str):
raise HTTPException(
status_code=400, detail="No student_quiz_report found"
)

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": 400

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status code should be 404. Resource is not found. 400 is bad request.

}
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 %}