Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Failed to process and send notifications #161

Closed
almereyda opened this issue Mar 2, 2022 · 2 comments
Closed

Failed to process and send notifications #161

almereyda opened this issue Mar 2, 2022 · 2 comments
Milestone

Comments

@almereyda
Copy link

almereyda commented Mar 2, 2022

What's this issue about?

When attempting to use email notifications after sending, the API outputs an error.

The admin had previously received their welcome mail, which suggests that transport is working as expected.

Also sign up mails are delivered.

Expected behavior

Email notifications are being sent.

Actual behavior

When finishing a submission, no error is thrown for the user, but the API shows:

{
  "level": 50,
  "time": 1646183135643,
  "pid": 35,
  "hostname": "5177d2cc673f",
  "req": {
    "id": 13,
    "method": "POST",
    "url": "/graphql",
    "query": {},
    "params": {
      "0": "graphql"
    },
    "headers": {
      "host": "forms.example.com",
      "user-agent": "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0",
      "content-length": "243",
      "accept": "*/*",
      "accept-encoding": "gzip, deflate, br",
      "accept-language": "de,en-US;q=0.7,en;q=0.3",
      "content-type": "application/json",
      "dnt": "1",
      "origin": "https://forms.example.com",
      "referer": "https://forms.example.com/form/jP5Nn3",
      "sec-fetch-dest": "empty",
      "sec-fetch-mode": "cors",
      "sec-fetch-site": "same-origin",
      "sec-gpc": "1",
      "te": "trailers",
      "x-forwarded-for": "redacted",
      "x-forwarded-host": "forms.example.com",
      "x-forwarded-port": "443",
      "x-forwarded-proto": "https",
      "x-forwarded-server": "efd9aa5bde2d",
      "x-real-ip": "redacted"
    },
    "remoteAddress": "::ffff:172.19.0.2",
    "remotePort": 56098
  },
  "context": "SubmissionNotificationService",
  "form": 1,
  "submission": 13,
  "notification": 1,
  "error": {
    "name": "TypeError",
    "message": "Cannot read property 'id' of undefined",
    "stack": "TypeError: Cannot read property 'id' of undefined\n    at /usr/src/app/dist/service/submission/submission.notification.service.js:35:75\n    at Array.map (<anonymous>)\n    at SubmissionNotificationService.process (/usr/src/app/dist/service/submission/submission.notification.service.js:30:57)\n    at SubmissionSetFieldService.finishSubmission (/usr/src/app/dist/service/submission/submission.set.field.service.js:75:28)\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)\n    at async SubmissionFinishMutation.submissionFinish (/usr/src/app/dist/resolver/submission/submission.finish.mutation.js:32:9)\n    at async target (/usr/src/app/node_modules/@nestjs/core/helpers/external-context-creator.js:77:28)\n    at async Object.submissionFinish (/usr/src/app/node_modules/@nestjs/core/helpers/external-proxy.js:9:24)"
  },
  "msg": "failed to process notification"
}
TypeError: Cannot read property 'id' of undefined
    at /usr/src/app/dist/service/submission/submission.notification.service.js:35:75
    at Array.map (<anonymous>)
    at SubmissionNotificationService.process (/usr/src/app/dist/service/submission/submission.notification.service.js:30:57)
    at SubmissionSetFieldService.finishSubmission (/usr/src/app/dist/service/submission/submission.set.field.service.js:75:28)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async SubmissionFinishMutation.submissionFinish (/usr/src/app/dist/resolver/submission/submission.finish.mutation.js:32:9)
    at async target (/usr/src/app/node_modules/@nestjs/core/helpers/external-context-creator.js:77:28)
    at async Object.submissionFinish (/usr/src/app/node_modules/@nestjs/core/helpers/external-proxy.js:9:24)

{
  "level": 50,
  "time": 1646183135643,
  "pid": 35,
  "hostname": "5177d2cc673f",
  "req": {
    "id": 13,
    "method": "POST",
    "url": "/graphql",
    "query": {},
    "params": {
      "0": "graphql"
    },
    "headers": {
      "host": "forms.example.com",
      "user-agent": "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0",
      "content-length": "243",
      "accept": "*/*",
      "accept-encoding": "gzip, deflate, br",
      "accept-language": "de,en-US;q=0.7,en;q=0.3",
      "content-type": "application/json",
      "dnt": "1",
      "origin": "https://forms.example.com",
      "referer": "https://forms.example.com/form/jP5Nn3",
      "sec-fetch-dest": "empty",
      "sec-fetch-mode": "cors",
      "sec-fetch-site": "same-origin",
      "sec-gpc": "1",
      "te": "trailers",
      "x-forwarded-for": "redacted",
      "x-forwarded-host": "forms.example.com",
      "x-forwarded-port": "443",
      "x-forwarded-proto": "https",
      "x-forwarded-server": "efd9aa5bde2d",
      "x-real-ip": "redacted"
    },
    "remoteAddress": "::ffff:172.19.0.2",
    "remotePort": 56098
  },
  "context": "SubmissionSetFieldService",
  "submission": 13,
  "form": 1,
  "error": {
    "name": "TypeError",
    "message": "Cannot read property 'id' of undefined",
    "stack": "TypeError: Cannot read property 'id' of undefined\n    at /usr/src/app/dist/service/submission/submission.notification.service.js:35:75\n    at Array.map (<anonymous>)\n    at SubmissionNotificationService.process (/usr/src/app/dist/service/submission/submission.notification.service.js:30:57)\n    at SubmissionSetFieldService.finishSubmission (/usr/src/app/dist/service/submission/submission.set.field.service.js:75:28)\n  at processTicksAndRejections (internal/process/task_queues.js:95:5)\n    at async SubmissionFinishMutation.submissionFinish (/usr/src/app/dist/resolver/submission/submission.finish.mutation.js:32:9)\n    at async target (/usr/src/app/node_modules/@nestjs/core/helpers/external-context-creator.js:77:28)\n    at async Object.submissionFinish (/usr/src/app/node_modules/@nestjs/core/helpers/external-proxy.js:9:24)"
  },
  "msg": "failed to send notifications"
}
TypeError: Cannot read property 'id' of undefined
    at /usr/src/app/dist/service/submission/submission.notification.service.js:35:75
    at Array.map (<anonymous>)
    at SubmissionNotificationService.process (/usr/src/app/dist/service/submission/submission.notification.service.js:30:57)
    at SubmissionSetFieldService.finishSubmission (/usr/src/app/dist/service/submission/submission.set.field.service.js:75:28)
  at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async SubmissionFinishMutation.submissionFinish (/usr/src/app/dist/resolver/submission/submission.finish.mutation.js:32:9)
    at async target (/usr/src/app/node_modules/@nestjs/core/helpers/external-context-creator.js:77:28)
    at async Object.submissionFinish (/usr/src/app/node_modules/@nestjs/core/helpers/external-proxy.js:9:24)

Then, no notifications are being sent.

This is verifiable at the email server, where no connection attempt is recorded.

Steps to reproduce

  1. Create a public form.
  2. Finish a submission.

Environment

This is the Docker setup using individual containers rolling from latest behind a Traefik proxy:

docker-compose.yml
version: "3"
services:
  redis:
    image: redis:6-alpine
    volumes:
    - /data/bases/redis/forms.example.com:/data
    networks:
    - internal

  postgres:
    image: postgres:10-alpine
    volumes:
    - /data/bases/postgres/forms.example.com:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: com-example-forms
      POSTGRES_PASSWORD: 
      POSTGRES_DB: com-example-forms
    networks:
    - internal

  ui:
#    image: ohmyform/ui
    build:
      context: ./ui
    environment:
#      ENDPOINT: http://localhost:8090/graphql
      ENDPOINT: /graphql
      SERVER_ENDPOINT: http://api:5000/graphql
      PORT: 5000
    expose:
      - "5000"
    networks:
    - internal
    - web
    labels:
      traefik.enable: true

      traefik.http.routers.com-example-forms-ui-web.entrypoints: web
      traefik.http.routers.com-example-forms-ui-web.rule: Host(`forms.example.com`)
      traefik.http.routers.com-example-forms-ui-web.middlewares: http-to-https

      traefik.http.middlewares.http-to-https.redirectscheme.scheme: https
      traefik.http.middlewares.http-to-https.redirectscheme.permanent: true

      traefik.http.routers.com-example-forms-ui-web-secure.entrypoints: web-secure
      traefik.http.routers.com-example-forms-ui-web-secure.rule: Host(`forms.example.com`)
      traefik.http.routers.com-example-forms-ui-web-secure.tls: true
      traefik.http.routers.com-example-forms-ui-web-secure.tls.certresolver: letsencrypt

  api:
    image: ohmyform/api
    environment:
      CREATE_ADMIN: "true"
      ADMIN_EMAIL: [email protected]
      ADMIN_USERNAME: example
      ADMIN_PASSWORD: 
      DATABASE_DRIVER: postgres
      DATABASE_URL: postgresql://com-example-forms:@postgres:5432/com-example-forms
      MAILER_URI: smtps://forms%40example.com:@mail.example.com:465/?pool=true
      MAILER_FROM: "Example Forms <[email protected]>"
      REDIS_HOST: redis
      SECRET_KEY: 
      BASE_URL: https://forms.example.com
    depends_on:
    - postgres
    - redis
    networks:
    - internal
    - web
    labels:
      traefik.enable: true

      traefik.http.routers.com-example-forms-api-web.entrypoints: web
      traefik.http.routers.com-example-forms-api-web.rule: Host(`forms.example.com`) && PathPrefix(`/graphql`)
      traefik.http.routers.com-example-forms-api-web.middlewares: http-to-https

      traefik.http.middlewares.http-to-https.redirectscheme.scheme: https
      traefik.http.middlewares.http-to-https.redirectscheme.permanent: true

      traefik.http.routers.com-example-forms-api-web-secure.entrypoints: web-secure
      traefik.http.routers.com-example-forms-api-web-secure.rule: Host(`forms.example.com`) && PathPrefix(`/graphql`)
      traefik.http.routers.com-example-forms-api-web-secure.tls: true
      traefik.http.routers.com-example-forms-api-web-secure.tls.certresolver: letsencrypt

networks:
  web:
    external: true
  internal:

Plus the Dockerfile from ohmyform/ui#72 in ./ui/Dockerfile.

@almereyda
Copy link
Author

almereyda commented Mar 2, 2022

Also it seems it's not clear which fields are required to be filled in a notification, which are optional, and which are mutually exclusive, because the red stars just appear and disappear seemingly randomly when selecting certain settings. This is eventually related to using a hidden form field that is set to a default value, which can be witnessed in #163, and used for determining the target address of a selected notification. The default value of the hidden form field is not present in the export, nor in the expanded submissions in their overview listing.

@wodka wodka added this to the 1.0.2 milestone Mar 13, 2022
@wodka
Copy link
Contributor

wodka commented Mar 13, 2022

fixed in ohmyform/api@30c2bc9

@wodka wodka closed this as completed Mar 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants