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

protect against the scenario when langlinks is undefined #55

Merged
merged 2 commits into from
Jan 13, 2024
Merged

protect against the scenario when langlinks is undefined #55

merged 2 commits into from
Jan 13, 2024

Conversation

yg-i
Copy link
Contributor

@yg-i yg-i commented Nov 28, 2023

For some pages, the langLinks property is undefined, and the current implementation throws an error. An example:

import wiki from 'wikipedia'
const pageObj = await wiki.page('TheBrain')
const langLinks = await pageObj.langLinks()

throws the error:

linksError: linksError: TypeError: Cannot read properties of undefined (reading 'map')
    at Page.langLinks (...node_modules\wikipedia\dist\page.js:234:23)

This PR is so that langLinks() returns an empty array rather than throws an error.

For some pages, the langlinks property is undefined, and the current implementation throws an error. An example:
```
import wiki from 'wikipedia'
const pageObj = await wiki.page('TheBrain')
const langLinks = await pageObj.langLinks()
```
throws the error:
```
linksError: linksError: TypeError: Cannot read properties of undefined (reading 'map')
    at Page.langLinks (...node_modules\wikipedia\dist\page.js:234:23)
```

This PR is so that langLinks() returns an empty array rather than throws an error
@dopecodez
Copy link
Owner

Thanks for the PR @yg-i - it makes sense considering the sheer number of languages wikipedia supports that we should have this validation.
Could you add a test for the same or i will add one over this weekend and merge this mr.

@dopecodez dopecodez merged commit 121a05e into dopecodez:master Jan 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants