getSubredditByName fails when trying to retrieve details of gated subreddits
Some subreddits, like /r/drugs, have an interstitial warning that includes a content advisory and helpline details. This causes getSubredditByName to fail when trying to retrieve the subreddit details
e.g.
const sub = await context.reddit.getSubredditByName("drugs");
console.log(sub);
fails with error:
Error: Get "https://oauth.reddit.com/r/drugs/about?raw_json=1": httpbp.ClientError: http status 403 Forbidden: {"interstitial_warning_message_html": "\u003C!-- SC_OFF --\u003E\u003Cdiv class=\"md\"\u003E\u003Cp\u003EContent Advisory: This community may contain discussions and content pertaining to drug use and abuse. It may be triggering for those in recovery and readers should proceed with caution. If you or someone you know is struggling with addiction or substance abuse, SAMHSA provides free 24/7 support and resources in a variety of languages at \u003Ca href=\"https://www.samhsa.gov/find-help/national-helpline\"\u003Ehttps://www.samhsa.gov/find-help/national-helpline\u003C/a\u003E, or call 1-800-662-HELP (4357).\u003C/p\u003E\n\u003C/div\u003E\u003C!-- SC_ON --\u003E", "reason": "gated", "interstitial_warning_message": "Content Advisory: This community may contain discussions and content pertaining to drug use and abuse. It may be triggering for those in recovery and readers should proceed with caution. If you or someone you know is struggling with addiction or substance abuse, SAMHSA provides free 24/7 support an
at envelopeAsError (worker.bootstrap.cjs (c53b6935-51d4-4c53-a354-8c1587e08f6d.local):116622:12)
at Object.__privateGet (worker.bootstrap.cjs (c53b6935-51d4-4c53-a354-8c1587e08f6d.local):117343:18)
at EnvelopeClient.post (worker.bootstrap.cjs (c53b6935-51d4-4c53-a354-8c1587e08f6d.local):117319:64)
at WorkerDispatcher.dispatchFilteredResponse_fn (worker.bootstrap.cjs (c53b6935-51d4-4c53-a354-8c1587e08f6d.local):118048:24)
at WorkerDispatcher.dispatchFiltered_fn (worker.bootstrap.cjs (c53b6935-51d4-4c53-a354-8c1587e08f6d.local):117994:83)
at WorkerDispatcher.postAsync_fn (worker.bootstrap.cjs (c53b6935-51d4-4c53-a354-8c1587e08f6d.local):118259:65)
at WorkerDispatcher.post (worker.bootstrap.cjs (c53b6935-51d4-4c53-a354-8c1587e08f6d.local):117960:53)
at PortEnvelopeRecipient.onMessage (worker.bootstrap.cjs (c53b6935-51d4-4c53-a354-8c1587e08f6d.local):118309:38)
at __privateGet.onmessage (worker.bootstrap.cjs (c53b6935-51d4-4c53-a354-8c1587e08f6d.local):118296:59)
at <anonymous>:1:1
The same error occurs on getSubredditById("t5_2qh7l"). It may be also worth checking getCurrentSubreddit(), because it may cause issues with the use of Devvit apps in general on gated subreddits.
This should be resolved for most* gated subreddits now.
The functions getSubredditByName() and getSubredditById() are deprecated in favor of getSubredditInfoByName() and getSubredditInfoById() (related commit). The new functions are able to bypass the gated check and return a similar set of info.
*most: meaning, everything except quarantined subreddits. I'm working on making it so that getSubredditInfoByName() and getSubredditInfoById() can also read quarantined subreddits, but there's a few internal dependencies I'm waiting on before I can do that.
I just tried out getSubredditInfoByName on /r/drugs and it worked fine, so that's awesome.
For completeness, I tried it on a quarantined subreddit (e.g. TheRedPill) and that still fails.
For completeness, I tried it on a quarantined subreddit (e.g. TheRedPill) and that still fails
yeah, I'm keeping this issue open until we can fetch quarantined subreddits with the new methods. Will let you know when the updates are in!
There are some concerns internally about returning information for quarantined subreddits, especially if users haven't opted-in to viewing the subreddit's content. I'd like to leave the behavior as-is (and simply not return info if the subreddit is quarantined).
If there's a specific usecase where the quarantined subreddit info is really needed, I would start a discussion about it in Discord. For now though I'm going to close this issue.