Skip to content

Commit 6efc422

Browse files
Report error when fetching ListGroupRights fails.
1 parent c3f6809 commit 6efc422

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

highlight.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Ajv, {JSONSchemaType} from 'ajv';
22
import {Mwn} from 'mwn';
33
import parser from 'node-html-parser';
44

5+
const USER_AGENT = 'Highlight.css updater';
6+
57
interface Config {
68
groups: {
79
[key: string]: {
@@ -78,8 +80,15 @@ async function getUsers({groups, overrides}: Config) {
7880
searchParams[`groups[${index++}]`] = group;
7981
users[group] = [];
8082
}
81-
const response = await fetch(`https://dev.fandom.com/wiki/Special:ListGlobalUsers?${new URLSearchParams(searchParams)}`);
83+
const response = await fetch(`https://dev.fandom.com/wiki/Special:ListGlobalUsers?${new URLSearchParams(searchParams)}`, {
84+
headers: {
85+
'User-Agent': USER_AGENT,
86+
},
87+
});
8288
const html = await response.text();
89+
if (!response.ok) {
90+
throw new Error(`failed to fetch user group list: status code ${response.status}, response: ${html}`);
91+
}
8392
const tree = parser.parse(html);
8493
for (const node of tree.querySelectorAll('.list-global-users-members > li')) {
8594
const name = node.querySelector('bdi')?.innerText;
@@ -129,7 +138,7 @@ async function init() {
129138
apiUrl: 'https://dev.fandom.com/api.php',
130139
password: process.env.PASSWORD,
131140
silent: true,
132-
userAgent: 'Highlight.css updater',
141+
userAgent: USER_AGENT,
133142
username: process.env.USERNAME,
134143
});
135144
await bot.login();

0 commit comments

Comments
 (0)