reddit / devvit

Reddit for Developers
https://developers.reddit.com
BSD 3-Clause "New" or "Revised" License
59 stars 13 forks source link

getSubredditByName fails when trying to retrieve details of gated subreddits #66

Open fsvreddit opened 3 months ago

fsvreddit commented 3 months ago

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.