not-an-aardvark / snoowrap

A JavaScript wrapper for the reddit API
MIT License
1.01k stars 125 forks source link

subreddit.getWikiPage(args).fetch() returns promise resolved with malformed WikiPage object #351

Open JamesxX opened 2 years ago

JamesxX commented 2 years ago

In the example code below:

mySubreddit.getWikiPage(args).fetch().then( wiki: Snoowrap.WikiPage ) =>{
    /// Do Stuff
    wiki.edit({
        text: edittedWikiPage,
        reason: 'reason',
    });
})

produces the below error:

url: "r/".concat(_this4.subreddit.display_name, "/api/wiki/edit"),
                                          ^

TypeError: Cannot read properties of undefined (reading 'display_name')

Internally, _this4.subreddit appears to be undefined, with no opportunity to remedy.

iMrDJAi commented 2 years ago

@JamesxX Fixed by adding:

_transformApiResponse (res: WikiPage) {
  res.title = this.title
  res.subreddit = this.subreddit
  return res
}

...to the WikiPage class.