dopecodez / Wikipedia

Wikipedia for node and the browser
MIT License
82 stars 19 forks source link

protect against the scenario when langlinks is undefined #55

Closed yg-i closed 10 months ago

yg-i commented 11 months ago

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 commented 11 months ago

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.