-
Notifications
You must be signed in to change notification settings - Fork 23
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
Theme config does not take effect #155
Conversation
lcduong
commented
Jul 16, 2024
•
edited
Loading
edited
Note: for upload logo file, [urls] [media] must be configured in config file since /media is expose by server app, so need to config nginx for expose via webapp. |
server/venueless/zoom/views.py
Outdated
@@ -53,7 +54,8 @@ def get_closest_zoom_lang(world): | |||
class ZoomViewMixin: | |||
@cached_property | |||
def world(self): | |||
w = get_object_or_404(World, domain=self.request.headers["Host"]) | |||
world_domain = re.sub(r":\d+$", "", self.request.headers["Host"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Django's built-in request.get_host()
.
server/venueless/api/views.py
Outdated
@return: theme data of a world | ||
""" | ||
world = get_object_or_404(World, id=kwargs["world_id"]) | ||
return Response(WorldSerializer(world).data['config']['theme']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please handle KeyError
.
I think it is not safe to assume that the API response is always in the shape that the frontend expects (like missing some fields, or different data type). In the future, when we can migrate our frontend to Vue 3 + TypeScript, this "validation step" will be mandatory, because not only it help developers to find where data is wrong, but also provide type information (TypeScript) for IDE to produce good autocomplete. |
try: | ||
world = get_object_or_404(World, id=kwargs["world_id"]) | ||
return Response(WorldSerializer(world).data['config']['theme']) | ||
except KeyError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If KeyError
happens, it means that us, the website owner, did not prepare enough data, or misconfigured the website. We need to do logger.error
to inform our team.
For end user, we can throw error 503 to tell that this error is our side, temporary and can work again in the future.
server/venueless/api/views.py
Outdated
world = get_object_or_404(World, id=kwargs["world_id"]) | ||
return Response(WorldSerializer(world).data['config']['theme']) | ||
except KeyError: | ||
logger.error(f"error happened when trying to get theme data of world: " + kwargs["world_id"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect use of logger. Check guide in fossasia/eventyay-talk#130