Skip to content

Commit e604ea8

Browse files
authored
Merge pull request #1874 from rocket-admin/backend_slack_message
feat(slack): enhance error handling and logging in slackPostMessage function
2 parents 6b2e3b7 + 31728e7 commit e604ea8

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

backend/src/helpers/slack/slack-post-message.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Sentry from '@sentry/minimal';
12
import axios from 'axios';
23
import { appConfig } from '../../shared/config/app-config.js';
34
import { Constants } from '../constants/constants.js';
@@ -17,8 +18,20 @@ export async function slackPostMessage(message: string, channel = Constants.DEFA
1718
},
1819
{ headers: { authorization: `Bearer ${slackBotToken}` } },
1920
);
21+
const data = res.data as { ok?: boolean; error?: string };
22+
if (data && data.ok === false) {
23+
// Slack accepted the HTTP call but refused the post (revoked token, unknown channel…).
24+
// Slack is the ops pager — it silently failing is itself an incident, so report through
25+
// the one channel that still works. Cannot use WinstonLogger here (it imports this helper).
26+
console.error(`slackPostMessage rejected by Slack API: ${data.error}`);
27+
Sentry.captureMessage(`slackPostMessage rejected by Slack API: ${data.error}`);
28+
}
2029
return res.data;
21-
} catch (_e) {
30+
} catch (e) {
31+
// Same reasoning as above: a broken alerting channel must not be invisible. Still swallowed —
32+
// posting must never affect the operation that triggered it.
33+
console.error('slackPostMessage failed:', e);
34+
Sentry.captureException(e);
2235
return;
2336
}
2437
}

0 commit comments

Comments
 (0)