fix: add try-catch to Discourse data scrubbing

This commit is contained in:
Jonathan Barrow
2025-10-03 16:22:17 -04:00
parent d699a5efdb
commit 6e99715f85

View File

@@ -249,18 +249,22 @@ PNIDSchema.method('scrub', async function scrub() {
}
if (config.discourse.forum_url && config.discourse.api_key && config.discourse.api_username) {
const response = await fetch(`${config.discourse.forum_url}/u/by-external/${this.pid}.json`);
const json = await response.json();
try {
const response = await fetch(`${config.discourse.forum_url}/u/by-external/${this.pid}.json`);
const json = await response.json();
if (!json.errors && json.user) {
await fetch(`${config.discourse.forum_url}/admin/users/${json.user.id}/anonymize.json`, {
method: 'PUT',
headers: {
'content-type': 'application/json',
'Api-Key': config.discourse.api_key,
'Api-Username': config.discourse.api_username
}
});
if (!json.errors && json.user) {
await fetch(`${config.discourse.forum_url}/admin/users/${json.user.id}/anonymize.json`, {
method: 'PUT',
headers: {
'content-type': 'application/json',
'Api-Key': config.discourse.api_key,
'Api-Username': config.discourse.api_username
}
});
}
} catch (error) {
LOG_ERROR(`ERROR REMOVING ${this.username} FORUM DATA. ${error}`);
}
}