#Cacti's issue
1 messages · Page 1 of 1 (latest)
so pretty simply, this is kinda just a clash because you're using both await and .then
ah
But if you just return the fetch, and await it where you call getRedditPost
It should work fine
Combining await with .then means that it will resolve to the return value of the last .then in the chain
alright, ill remove the await before the fetch, and await the function instead
Make sure you return the fetch though
Oh, but I do all the processing in the function
Well like
Here's another approach
async function getRedditPost(subreddit) {
- await fetch(`https://www.reddit.com/r/${subreddit}/random/.json`, { method: 'Get' }) // random reddit post
+ const response = await fetch(`https://www.reddit.com/r/${subreddit}/random/.json`, { method: 'Get' }) // random reddit post
- .then(async response => {
const [list] = await response.json();
Just get rid of the .then completely and stick to using await
Cool. Its possible to use await and then together but generally, its best just to pick one style of handling promises and stick to it
I prefer await
noted, I'll have to remember this if I experience a similar problem in the future
mind if I add your name at the top of the file?:
// Credit to Monbrey#4502 on Discord for helping me out on a bit of processing
lol sure