Open pthieu opened 6 years ago
Hi,
Could you share the code that you're using? It's hard to tell what's going on without any code. My best guess is that you are trying to get information about a user whose account has been deleted.
my core code is something like this:
const Snoowrap = require('snoowrap');
const config = require('./config')
const redditOpts = {
userAgent: config.REDDIT_USER_AGENT,
clientId: config.REDDIT_CLIENT_ID,
clientSecret: config.REDDIT_CLIENT_SECRET,
refreshToken: config.REDDIT_REFRESH_TOKEN,
};
const r = new Snoowrap(redditOpts);
async const main() {
const results = [];
const comments = [];
const redditId = post.reddit_id;
const submission = await r.getSubmission(redditId);
results.push(submission)
const commentsData = await submission.fetch().comments
const comments = comments.concat(...commentsData);
}
I think submission.fetch()
might be fetching everything that's in the Submission Listing? including user.
Anyway, I swapped all these calls with the browser .json
requests since they're all GET
requests and the rate-limit errors went away
These errors seem to happen when the author of a submission is deleted. This is not immediately clear as the error being thrown is just that, the invalid username '[deleted]'.
r.getSubmission('9ka5gm').author.fetch().then(console.log); // unhandled rejection (Error: [deleted])
r.getSubmission('9ka5gm').author.then(console.log); // RedditUser { name: '[deleted]' } (no error, no unhandled rejection)
r.getSubmission('9ka5gm').author.then(a => console.log(a.name)); //[deleted] (no error, no unhandled rejection)
r.getSubmission('9ka5gm').author.then(a => console.log(a.is_suspended)); // unhandled rejection (Error: [deleted])
r.getUser('[deleted]').fetch().then(console.log); // (Error: [deleted]) (thrown error, instead of unhandled rejection)
r.getUser('deleted').fetch().then(console.log); // RedditUser { is_suspended: true, name: 'deleted' } (real user, no error)
Putting the right .catch() 'es in the examples above is easy but i needed a workaround for some business logic i couldn't change, so i ended up with something like:
if(post.author.name == '[deleted]'){
console.log('Avoiding snoowrap failures by changing crossposted author [deleted] to deleted');
post.author.name = 'deleted';
}
business logic doing stuff with post;
Authors can also be in embedded crossposts, so also check
if(post.crosspost_parent_list && post.crosspost_parent_list[0].author.name == '[deleted]'){
console.log('Avoiding snoowrap failures by changing crossposted author [deleted] to deleted');
post.crosspost_parent_list[0].author.name = 'deleted';
}
Not sure if there's more places where there can be a [deleted] author.
I've not been able to reproduce this as I can't figure out how this could occur in the code-snippet
I'm getting this unhandled error:
I'm actually not sure where this is coming from as all I'm doing are
r.getSubmission
's andsubmission.fetch().comments
'sI've put
try-catch
blocks on any snoowrap call so I'm thinking there must be something happening like a heartbeat or something under the hood.This error also makes me think something is happening under the hood as I'm only making 5 api calls every 30 seconds, which comes out to be 10 a minute, 100 per 10 minutes which is under reddit's API limits.