Clearer error message on wiki content failed response

This commit is contained in:
FoxxMD
2021-07-31 23:08:32 -04:00
parent 8b1d3cb170
commit 3a05e43ce9
2 changed files with 12 additions and 4 deletions

View File

@@ -36,7 +36,7 @@ export class MessageAction extends Action {
async process(item: Comment | Submission, ruleResults: RuleResult[], runtimeDryrun?: boolean): Promise<void> {
const dryRun = runtimeDryrun || this.dryRun;
const content = await this.resources.getContent(this.content, item.subreddit);
const content = await this.resources.getContent(this.content);
const body = await renderContent(content, item, ruleResults, this.resources.userNotes);
const footer = await this.resources.generateFooter(item, this.footer);

View File

@@ -3,7 +3,7 @@ import objectHash from 'object-hash';
import {
AuthorActivitiesOptions,
AuthorTypedActivitiesOptions, BOT_LINK,
getAuthorActivities,
getAuthorActivities, singleton,
testAuthorCriteria
} from "../Utils/SnoowrapUtils";
import Subreddit from 'snoowrap/dist/objects/Subreddit';
@@ -215,14 +215,22 @@ export class SubredditResources {
sub = subreddit;
} else {
// @ts-ignore
const client = subreddit._r as Snoowrap;
const client = singleton.getClient();
sub = client.getSubreddit(wikiContext.subreddit);
}
try {
// @ts-ignore
const wikiPage = sub.getWikiPage(wikiContext.wiki);
wikiContent = await wikiPage.content_md;
} catch (err) {
const msg = `Could not read wiki page. Please ensure the page 'https://reddit.com${sub.display_name_prefixed}wiki/${wikiContext}' exists and is readable`;
let msg = `Could not read wiki page for an unknown reason. Please ensure the page 'https://reddit.com${sub.display_name_prefixed}wiki/${wikiContext.wiki}' exists and is readable`;
if(err.statusCode !== undefined) {
if(err.statusCode === 404) {
msg = `Could not find a wiki page at https://reddit.com${sub.display_name_prefixed}wiki/${wikiContext.wiki} -- Reddit returned a 404`;
} else if(err.statusCode === 403 || err.statusCode === 401) {
msg = `Bot either does not have permission visibility permissions for the wiki page at https://reddit.com${sub.display_name_prefixed}wiki/${wikiContext.wiki} (due to subreddit restrictions) or the bot does have have oauth permissions to read wiki pages (operator error). Reddit returned a ${err.statusCode}`;
}
}
this.logger.error(msg, err);
throw new LoggedError(msg);
}