Skip to content

Commit

Permalink
Catch validation errors in aplus_json
Browse files Browse the repository at this point in the history
Validation errors shouldn't really happen in production but might
happen while developing
  • Loading branch information
lainets committed Aug 28, 2023
1 parent ac20197 commit d1044e4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions access/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.utils import translation
from django.urls import reverse
from django.views import View
from pydantic.error_wrappers import ValidationError

from access.config import ConfigSource, CourseConfig
from access.course import Exercise, Chapter, Parent
Expand Down Expand Up @@ -189,7 +190,7 @@ def aplus_json(request: HttpRequest, course_key: str) -> HttpResponse:
if os.path.exists(CourseConfig.path_to(course_key, source=ConfigSource.STORE)):
try:
config = CourseConfig.get(course_key, source=ConfigSource.STORE)
except ConfigError as e:
except (ConfigError, ValidationError) as e:
errors.append(f"Failed to load newly built course due to this error: {e}")
errors.append("Attempting to load previous version of the course...")
logger.warn(f"Failed to load newly built course due to this error: {e}")
Expand All @@ -199,7 +200,7 @@ def aplus_json(request: HttpRequest, course_key: str) -> HttpResponse:
if config is None:
try:
config = CourseConfig.get(course_key, source=ConfigSource.PUBLISH)
except ConfigError as e:
except (ConfigError, ValidationError) as e:
logger.error(f"aplus_json: failed to get config for {course_key}")
try:
Course.objects.get(key=course_key)
Expand Down

0 comments on commit d1044e4

Please sign in to comment.