Skip to content
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

Cannot read property "token" of undefined #25

Open
jvgeee opened this issue Sep 8, 2020 · 1 comment
Open

Cannot read property "token" of undefined #25

jvgeee opened this issue Sep 8, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@jvgeee
Copy link

jvgeee commented Sep 8, 2020

Using the sample code in the readme to fetch a form, I'm getting:

(node:23596) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'token' of undefined
    at Form._fetchResponses (~/node_modules/@lirantal/typeform-client/src/Form/Form.js:95:31)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Form.fetchFormResponses ~/node_modules/@lirantal/typeform-client/src/Form/Form.js:118:51)
    at async ~/test.js:16:14

The error comes from this line in the node module:

      if (apiResult.page_count === 1) {
        break
      } else {
        const len = apiResult.items.length
        const lastItem = apiResult.items[len - 1]
        tokenValue = lastItem.token
      }

Might need a more defensive fix?

For reference, my form has 6 questions and no responses.

@lirantal lirantal self-assigned this Sep 9, 2020
@lirantal lirantal added the bug Something isn't working label Sep 9, 2020
@lirantal
Copy link
Owner

lirantal commented Sep 9, 2020

Hey @jascination, thanks for raising an issue.
Indeed looks like there's simply no more data to fetch and hence no token exists.

Would you want to submit a PR that fixes the issue? I'm happy to merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants