mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
Merge pull request #246 from iRubbish/feat/webhook-account-notification
feat: 添加账号禁用异常状态 Webhook 通知功能 (已格式化)
This commit is contained in:
@@ -228,6 +228,21 @@ class ClaudeAccountService {
|
||||
accountData.status = 'error'
|
||||
accountData.errorMessage = error.message
|
||||
await redis.setClaudeAccount(accountId, accountData)
|
||||
|
||||
// 发送Webhook通知
|
||||
try {
|
||||
const webhookNotifier = require('../utils/webhookNotifier')
|
||||
await webhookNotifier.sendAccountAnomalyNotification({
|
||||
accountId,
|
||||
accountName: accountData.name,
|
||||
platform: 'claude-oauth',
|
||||
status: 'error',
|
||||
errorCode: 'CLAUDE_OAUTH_ERROR',
|
||||
reason: `Token refresh failed: ${error.message}`
|
||||
})
|
||||
} catch (webhookError) {
|
||||
logger.error('Failed to send webhook notification:', webhookError)
|
||||
}
|
||||
}
|
||||
|
||||
logger.error(`❌ Failed to refresh token for account ${accountId}:`, error)
|
||||
@@ -1223,6 +1238,21 @@ class ClaudeAccountService {
|
||||
`⚠️ Account ${accountData.name} (${accountId}) marked as unauthorized and disabled for scheduling`
|
||||
)
|
||||
|
||||
// 发送Webhook通知
|
||||
try {
|
||||
const webhookNotifier = require('../utils/webhookNotifier')
|
||||
await webhookNotifier.sendAccountAnomalyNotification({
|
||||
accountId,
|
||||
accountName: accountData.name,
|
||||
platform: 'claude-oauth',
|
||||
status: 'unauthorized',
|
||||
errorCode: 'CLAUDE_OAUTH_UNAUTHORIZED',
|
||||
reason: 'Account unauthorized (401 errors detected)'
|
||||
})
|
||||
} catch (webhookError) {
|
||||
logger.error('Failed to send webhook notification:', webhookError)
|
||||
}
|
||||
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
logger.error(`❌ Failed to mark account ${accountId} as unauthorized:`, error)
|
||||
|
||||
@@ -403,6 +403,9 @@ class ClaudeConsoleAccountService {
|
||||
try {
|
||||
const client = redis.getClientSafe()
|
||||
|
||||
// 获取账户信息用于webhook通知
|
||||
const accountData = await client.hgetall(`${this.ACCOUNT_KEY_PREFIX}${accountId}`)
|
||||
|
||||
const updates = {
|
||||
status: 'blocked',
|
||||
errorMessage: reason,
|
||||
@@ -412,6 +415,24 @@ class ClaudeConsoleAccountService {
|
||||
await client.hset(`${this.ACCOUNT_KEY_PREFIX}${accountId}`, updates)
|
||||
|
||||
logger.warn(`🚫 Claude Console account blocked: ${accountId} - ${reason}`)
|
||||
|
||||
// 发送Webhook通知
|
||||
if (accountData && Object.keys(accountData).length > 0) {
|
||||
try {
|
||||
const webhookNotifier = require('../utils/webhookNotifier')
|
||||
await webhookNotifier.sendAccountAnomalyNotification({
|
||||
accountId,
|
||||
accountName: accountData.name || 'Unknown Account',
|
||||
platform: 'claude-console',
|
||||
status: 'blocked',
|
||||
errorCode: 'CLAUDE_CONSOLE_BLOCKED',
|
||||
reason
|
||||
})
|
||||
} catch (webhookError) {
|
||||
logger.error('Failed to send webhook notification:', webhookError)
|
||||
}
|
||||
}
|
||||
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
logger.error(`❌ Failed to block Claude Console account: ${accountId}`, error)
|
||||
|
||||
@@ -764,6 +764,21 @@ async function refreshAccountToken(accountId) {
|
||||
status: 'error',
|
||||
errorMessage: error.message
|
||||
})
|
||||
|
||||
// 发送Webhook通知
|
||||
try {
|
||||
const webhookNotifier = require('../utils/webhookNotifier')
|
||||
await webhookNotifier.sendAccountAnomalyNotification({
|
||||
accountId,
|
||||
accountName: account.name,
|
||||
platform: 'gemini',
|
||||
status: 'error',
|
||||
errorCode: 'GEMINI_ERROR',
|
||||
reason: `Token refresh failed: ${error.message}`
|
||||
})
|
||||
} catch (webhookError) {
|
||||
logger.error('Failed to send webhook notification:', webhookError)
|
||||
}
|
||||
} catch (updateError) {
|
||||
logger.error('Failed to update account status after refresh error:', updateError)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user