通知系统-1
This commit is contained in:
@@ -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 ''
|
||||
|
||||
Reference in New Issue
Block a user