Skip to content
Snippets Groups Projects
Commit d0923d56 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

fix: raise DRF-compatible exception for configuration errors

ValueError has no built-in handling in DRF causing it to return an HTML
error page. This is unfortunate for clients that expect a JSON error
object like the dashboard.
parent ab5e746f
No related branches found
No related tags found
1 merge request!55fix: raise DRF-compatible exception for configuration errors
Pipeline #8361 passed
from rest_framework import status
from rest_framework.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
class ConfigurationError(ValidationError):
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
default_detail = _("Invalid or insufficient server configuration.")
default_code = "misconfigured"
...@@ -30,6 +30,7 @@ from django.core.exceptions import ObjectDoesNotExist ...@@ -30,6 +30,7 @@ from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q, QuerySet from django.db.models import Q, QuerySet
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from program.exceptions import ConfigurationError
from program.models import ( from program.models import (
Note, Note,
ProgramEntry, ProgramEntry,
...@@ -745,7 +746,10 @@ def generate_program_entries( ...@@ -745,7 +746,10 @@ def generate_program_entries(
radio_settings: RadioSettings | None = RadioSettings.objects.first() radio_settings: RadioSettings | None = RadioSettings.objects.first()
fallback_show = radio_settings.fallback_show if radio_settings is not None else None fallback_show = radio_settings.fallback_show if radio_settings is not None else None
if fallback_show is None: if fallback_show is None:
raise ValueError("Radio settings must set fallback show if include_virtual is True.") raise ConfigurationError(
"Radio settings must define a fallback show if include_virtual is True.",
code="no-fallback-show-defined",
)
entry_start = start entry_start = start
timeslot: TimeSlot timeslot: TimeSlot
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment