Answer
Guard JSON parsing by using request.get_json(silent=True) and return a 400 error when the body is missing or invalid. Specifically: - In POST /users: data = request.get_json(silent=True); if not data: return 400 with message 'Request body must be valid JSON'; proceed to read name, email, role from data. - In PUT /users//settings: data = request.get_json(silent=True); if not data: return 400 with message 'Request body must be valid JSON'; proceed to read theme and notifications from data. This prevents NoneType from being dereferenced and provides a clear error to clients.
8caf1967-f80b-491b-b8a2-babaf73dc5cc
Guard JSON parsing by using request.get_json(silent=True) and return a 400 error when the body is missing or invalid. Specifically:
- In POST /users: data = request.get_json(silent=True); if not data: return 400 with message 'Request body must be valid JSON'; proceed to read name, email, role from data.
- In PUT /users//settings: data = request.get_json(silent=True); if not data: return 400 with message 'Request body must be valid JSON'; proceed to read theme and notifications from data. This prevents NoneType from being dereferenced and provides a clear error to clients.