Fixes error in theme switcher and adds samesite setting in set-cookie header #113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently switching themes results in both server-side and client side errors.
Server side:
ERROR:app:Exception on /set_theme/dark [GET]
Traceback (most recent call last):
File "/root/picamera2-WebUI/.venv/lib/python3.11/site-packages/flask/app.py", line 1511, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/picamera2-WebUI/.venv/lib/python3.11/site-packages/flask/app.py", line 920, in full_dispatch_request
return self.finalize_request(rv)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/picamera2-WebUI/.venv/lib/python3.11/site-packages/flask/app.py", line 939, in finalize_request
response = self.make_response(rv)
^^^^^^^^^^^^^^^^^^^^^^
File "/root/picamera2-WebUI/.venv/lib/python3.11/site-packages/flask/app.py", line 1212, in make_response
raise TypeError(
TypeError: The view function for 'set_theme' did not return a valid response. The function either returned None or ended without a return statement.
The root cause is that the route ends with a bare "return", which probably translates to "return None", and that makes Flask erroring out. The error is reported back to the client with an 5xx error code, which makes it log an error on the JS console.
Changing the return statement to return the "ok" object makes both server and client happy :)
Also, on the console there were messages about the cookie samesite setting missing, now it is set explicitly to the most permissive value.