(message: string, error?: Error, module?: string)
| 260 | let notifyingCriticalError = false; |
| 261 | |
| 262 | function notifySlackCriticalError(message: string, error?: Error, module?: string): void { |
| 263 | if (!OPS_ALERT_CHANNEL_ID) return; |
| 264 | if (notifyingCriticalError) return; |
| 265 | notifyingCriticalError = true; |
| 266 | |
| 267 | const safeMessage = sanitizeForSlack(message); |
| 268 | const safeStack = error?.stack ? sanitizeForSlack(error.stack.slice(0, 500)) : ''; |
| 269 | |
| 270 | import('../slack/client.js') |
| 271 | .then(({ sendChannelMessage, isSlackConfigured }) => { |
| 272 | if (!isSlackConfigured()) return; |
| 273 | return sendChannelMessage(OPS_ALERT_CHANNEL_ID!, { |
| 274 | text: `FATAL ERROR on ${process.env.FLY_APP_NAME || 'aao-server'}: ${safeMessage}`, |
| 275 | blocks: [ |
| 276 | { |
| 277 | type: 'section', |
| 278 | text: { |
| 279 | type: 'mrkdwn', |
| 280 | text: [ |
| 281 | `:rotating_light: *FATAL ERROR* on \`${process.env.FLY_APP_NAME || 'aao-server'}\``, |
| 282 | module ? `*Module:* \`${module}\`` : '', |
| 283 | `*Message:* ${safeMessage}`, |
| 284 | safeStack ? `\`\`\`${safeStack}\`\`\`` : '', |
| 285 | ].filter(Boolean).join('\n'), |
| 286 | }, |
| 287 | }, |
| 288 | ], |
| 289 | }); |
| 290 | }) |
| 291 | .catch(() => {}) |
| 292 | .finally(() => { notifyingCriticalError = false; }); |
| 293 | } |
no test coverage detected