Closed TheCuriousGoose closed 3 years ago
subslist
into getImage
as it is; there's no need to pick a random subreddit, because it is already picked inside the functionIf the issue still persists - let me know
The error still is there when a subreddit for example ecchi is requested
@TheCuriousGoose, I've found where was the problem and fixed it. Now posts from r/ecchi
are fetched correctly.
Please, update to 2.0.2-0
and check if the problem is still here.
npm install random-reddit@2.0.2-0
I've had this issue too with certain subreddits they crash my irc bot. Brb testing 2.0.2.
I still have this issue. I deleted node modules. Updated package.json "random-reddit": "^2.0.2-0",
. Then ran yarn install. Went to node_modules to check random-reddit/package.json and it says "version": "2.0.2-0",
.
Trying to query forementioned ecchi throws this error:
HTTP GET https://reddit.com//r/ecchi/random.json?limit=1 14:24:50
HTTP Successful GET /r/ecchi/random.json?limit=1 14:24:51
/mnt/e/degeneraatti/node_modules/random-reddit/dist/functions.js:15
utils_1.logger.trace('Response', child.data);
^
TypeError: Cannot read property 'data' of undefined
at Object.getPost (/mnt/e/degeneraatti/node_modules/random-reddit/dist/functions.js:15:44)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async getImage (/mnt/e/degeneraatti/node_modules/random-reddit/dist/functions.js:27:16)
at async RedditService.getRedditImage (/mnt/e/degeneraatti/dist/reddit/reddit.service.js:19:23)
at async /mnt/e/degeneraatti/dist/app.controller.js:35:31
the code I'm running
//reddit.service.ts
async getRedditImage(fromSubReddit: string) {
try {
const image = await getImage(fromSubReddit);
return image;
} catch (error) {
return error;
}
}
then I call it
//app.controller.ts
if (messageMatch && messageMatch.commandPrefix === '!r') {
const image = await this.redditService.getRedditImage(messageMatch.command).catch((error) => {
console.log('error: ', error)
})
const message = `result ${messageMatch.command} :: ${image ? image : 'ERROR'} `
console.log(message)
this.appService.replyToChannel(this.defaultChannel, message);
}
and reply to channel
//app.service.ts
public replyToChannel(channelName: string, message: string) {
const channel = this.channelMap.get(channelName);
channel.say(message);
}
I managed to stop it crashing by catching the errors for now.
Still having the same problem as @ex1tium, running practically the same code as before. also is there a way to disable the HTTP Get console message.
Thanks in advance
Hi;
Sorry for the multiple comments - git isn't cooperating with my brain.
I'm also having the same undefined issue on 2.0.2-0. My code is not quite as refined; but its work so far without much issue. r/ecchi
is the problematic subreddit in this case, but i've seen it on others as well.
async function getpic(fromSubreddit) {
console.log('received ${fromSubreddit}');
try {
const image = await getImage(fromSubreddit);
console.log('retrieved pic at ${image}');
return image;
} catch (error) {
console.log(error);
return error;
}
}
is called by
(async() => {
dataurl = await getpic(categories[command][0]);
message.reply(dataurl);
})();
And lastly the error:
TypeError: Cannot read property 'data' of undefined
at Object.getPost (D:\Desktop\discord bot\node_modules\random-reddit\dist\functions.js:15:44)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async getImage (D:\Desktop\discord bot\node_modules\random-reddit\dist\functions.js:27:16)
at async getpic (D:\Desktop\discord bot\bot2.js:49:17)
at async D:\Desktop\discord bot\bot2.js:168:15
@Tormidal, @ex1tium, @TheCuriousGoose, make sure you pass ecchi
(or ['ecchi']
) in the argument, not r/ecchi
The following code works correctly:
async function test() {
const image = await getImage('ecchi').catch(e => {
console.log(e);
return;
})
console.log(image);
}
test()
@mamoruuu
Hi,
I have copied your code exactly and triggered the function.
I've also removed package and made sure it was installed as 2.0.2-0 to confirm that it is not on an incorrect version. I've done the same with random-reddit's dependencies.
I'm at a loss at what else I can do on my end to try to help troubleshoot.
Well, I'm lost too :( this exact snippet of code work on my end.
But I use Linux. I have a theory that node-fetch
might work differently on Windows. I'm gonna check it tomorrow
Sounds good! I'll keep my eye on it and test it when its available :)
In the meantime, I'll see if I can get a Linux platform to run this off of.
@mamoruuu For what its worth; I spun up a Ubuntu 20.04 VM and still getting the same issue.
Here is my current modules on the VM as well:
If there is anything else I can provide that can help, let me know :)
It clearly says that the HTTP request was successful 🤔
So it's definitely the problem with handling the response (and not with the OS, how could I think about it?)
Sorry for delay, I'm still busy, I'll get to this problem asap
Happy to help, I've found a number of subreddits affected by the issue: Not sure if having multiple examples will help, but I figured it was worth noting in case there's similarities.
My guess is you catch the Cannot read property "data" of undefined
errors because the request that is sent to https://reddit.com/r/whatever_sub_you_want/random.json?limit=1
returns the following error:
{
"message": "Too Many Requests",
"error": 429
}
You can get such response if you run curl --location https://reddit.com/r/whatever_sub_you_want/random.json?limit=1
When I was testing different requests with curl to the same location the custom header User-Agent
works for me. I'll also added some more headers just in case.
I just released the version 2.0.2-1
, please, check if it solves your problem.
If you get errors, please re-run the same script with an environment variable CONSOLA_LEVEL=4
. Like this
CONSOLA_LEVEL=4 npm run start
This will output the actual response from the request in the console
Sorry for the delayed reaction, but now I only get 1 image and not a random one from the subreddit, I did noticed the image is the currently hot on the subreddit
Apologies, been a busy week as well -
As @TheCuriousGoose said, I am getting the same image repeatedly when requesting from a subreddit affected by the issue.
Sorry for the delayed reaction, but now I only get 1 image and not a random one from the subreddit, I did noticed the image is the currently hot on the subreddit
I think it's because they're not just hot on the subreddit - they're pinned by moderators.
Also further testing shows that putting /random.json?limit=1
doesn't seem to work - it just returns the first post from hot posts. So I just made getPost
to just get the list of posts and pick a random one myself.
Try 2.0.2-2
now, it should work fine now.
@TheCuriousGoose did the last version work for you?
@TheCuriousGoose did the last version work for you?
Yes it did, everything is fixed now
@TheCuriousGoose did the last version work for you?
Yes it did, everything is fixed now
Okay, I will release the proper version 2.0.2
with this fix now
I've been using this package for my discord bot and for some subreddits ive been having this error
using this code