通知系统-1

This commit is contained in:
yml2213
2026-05-14 17:29:12 +08:00
parent 91d74b3e59
commit b6c493d5e7
22 changed files with 1314 additions and 11 deletions
@@ -5,6 +5,7 @@ import https from 'node:https'
import { createHttpError } from '../../../utils/http.js'
import { logInfo } from '../../../utils/logger.js'
import { notifyCloudtentaclesAuthExpired } from '../../notification/domain-notifications.js'
import { buildCloudtentaclesHeaders, buildCloudtentaclesUrl, resolveCloudtentaclesConfig } from './shared.js'
export async function cloudtentaclesRequest(pathname, options = {}) {
@@ -41,9 +42,21 @@ export async function cloudtentaclesRequest(pathname, options = {}) {
}
if (options.requireBusinessSuccess !== false && Number(payload?.code ?? 1) !== 0) {
throw createHttpError(String(payload?.message || payload?.msg || 'cloudtentacles 接口返回失败'), {
statusCode: Number(options.businessErrorStatusCode || 400),
errorCode: String(options.businessErrorCode || 'cloudtentacles_business_error'),
const message = String(payload?.message || payload?.msg || 'cloudtentacles 接口返回失败')
const statusCode = Number(options.businessErrorStatusCode || 400)
const errorCode = String(options.businessErrorCode || 'cloudtentacles_business_error')
if (statusCode === 401 || isCloudtentaclesExpiredMessage(message)) {
await notifyCloudtentaclesAuthExpired({
pathname,
errorCode,
message,
})
}
throw createHttpError(message, {
statusCode,
errorCode,
})
}
@@ -73,6 +86,11 @@ export async function cloudtentaclesRequest(pathname, options = {}) {
}
}
function isCloudtentaclesExpiredMessage(message) {
const normalized = String(message || '').trim().toLowerCase()
return normalized.includes('expired') || normalized.includes('过期') || normalized.includes('失效')
}
function inferContentType(body) {
if (body == null) {
return ''