medic / cht-core

The CHT Core Framework makes it faster to build responsive, offline-first digital health apps that equip health workers to provide better care in their communities. It is a central resource of the Community Health Toolkit.
https://communityhealthtoolkit.org
GNU Affero General Public License v3.0
469 stars 218 forks source link

API logs error when privacy policies doc contains no privacy policies #9527

Open dianabarsan opened 1 month ago

dianabarsan commented 1 month ago

Describe the bug When the privacy policies doc lacks the privacy_policies property, API logs an error. However this error is not critical and does not inform the user of what they should do. An empty privacy policies doc can come from an incomplete, but not incorrect configuration.

This creates noise and confusion, and gets reported as the reason why API crashed.

To Reproduce Steps to reproduce the behavior:

  1. In your config folder, create a privacy-policies.json file, but leave it empty.
  2. Upload thid config.
  3. Relaunch API.
  4. See error

Expected behavior This should be logged as a warning, or inform the user on what to do.

Logs

2024-10-11T08:30:29.645 ERROR: Error retrieving privacy policies: Error: Invalid privacy-policies doc: missing required "privacy_policies" property
    at /service/api/src/services/privacy-policy.js:25:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 3)
    at async getLoginPageContents (/service/api/src/generate-service-worker.js:53:10)
    at async writeServiceWorkerFile (/service/api/src/generate-service-worker.js:101:23)
    at async Object.run (/service/api/src/generate-service-worker.js:154:5)
    at async /service/api/server.js:91:5 {
  [stack]: 'Error: Invalid privacy-policies doc: missing required "privacy_policies" property\n' +
    '    at /service/api/src/services/privacy-policy.js:25:15\n' +
    '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
    '    at async Promise.all (index 3)\n' +
    '    at async getLoginPageContents (/service/api/src/generate-service-worker.js:53:10)\n' +
    '    at async writeServiceWorkerFile (/service/api/src/generate-service-worker.js:101:23)\n' +
    '    at async Object.run (/service/api/src/generate-service-worker.js:154:5)\n' +
    '    at async /service/api/server.js:91:5',
  [message]: 'Invalid privacy-policies doc: missing required "privacy_policies" property'
} 

Environment