snoowrap icon indicating copy to clipboard operation
snoowrap copied to clipboard

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

Open jamesrswift opened this issue 3 years ago • 1 comments

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.

jamesrswift avatar Jan 15 '22 20:01 jamesrswift

@JamesxX Fixed by adding:

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

...to the WikiPage class.

iMrDJAi avatar Apr 09 '22 10:04 iMrDJAi