#Cacti's issue

1 messages · Page 1 of 1 (latest)

craggy saffron
#

Hm, it doesen't want to send lol

restive forge
craggy saffron
#

yep

primal bough
#

so pretty simply, this is kinda just a clash because you're using both await and .then

craggy saffron
#

ah

primal bough
#

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

craggy saffron
#

alright, ill remove the await before the fetch, and await the function instead

primal bough
#

Make sure you return the fetch though

craggy saffron
#

Oh, but I do all the processing in the function

primal bough
#

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

craggy saffron
#

oh alright

#

hang on

#

woa

#

it works

primal bough
#

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

craggy saffron
#

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
primal bough
#

lol sure

craggy saffron
#

👍

#

Thank you so much

#

and you too Joe

primal bough
#

no worries, you dont have to credit me at all

#

but thanks

craggy saffron
#

Gonna do it anyway lol

#

My headache is gone