Merge remote-tracking branch 'origin/qyqy_develop' into RM2_develop
This commit is contained in:
@@ -2,6 +2,11 @@ import { clearAuthSession, getAccessToken } from '/static/portal/common/auth.js'
|
||||
|
||||
const ENDPOINTS = Object.freeze({
|
||||
A034: { method: 'POST', path: '/api/v1/auth/tokens', auth: false },
|
||||
V001: { method: 'POST', path: '/api/v1/visitor-tokens', auth: false, raw: true },
|
||||
C001: { method: 'POST', path: '/api/v1/conversations', idempotent: true },
|
||||
C002: { method: 'GET', path: '/api/v1/conversations/{sessionId}' },
|
||||
C003: { method: 'GET', path: '/api/v1/conversations/{sessionId}/messages' },
|
||||
C005: { method: 'POST', path: '/api/v1/conversations/{sessionId}/handover-requests', idempotent: true },
|
||||
A035: { method: 'GET', path: '/api/v1/admin/roles' },
|
||||
A036: { method: 'GET', path: '/api/v1/admin/roles/{roleCode}' },
|
||||
A037: { method: 'GET', path: '/api/v1/admin/roles/{roleCode}/permissions' },
|
||||
@@ -46,6 +51,11 @@ const ENDPOINTS = Object.freeze({
|
||||
T007: { method: 'GET', path: '/api/v1/users/me/transactions' },
|
||||
T008: { method: 'GET', path: '/api/v1/users/me/transactions/{transactionNo}' },
|
||||
T009: { method: 'GET', path: '/api/v1/users/me/cash-ledger' },
|
||||
ADVISOR_PUBLISHED: { method: 'GET', path: '/api/v1/advisor/recommendations/published' },
|
||||
ADVISOR_GOAL: { method: 'GET', path: '/api/v1/advisor/investment-goals/current' },
|
||||
ADVISOR_ANALYSIS: { method: 'POST', path: '/api/v1/advisor/portfolio-analysis' },
|
||||
OFFSITE_MAILS: { method: 'GET', path: '/api/v1/offsite-fund/mails' },
|
||||
OFFSITE_MAILBOX: { method: 'GET', path: '/api/v1/offsite-fund/mailbox-status' },
|
||||
});
|
||||
|
||||
export class ApiError extends Error {
|
||||
@@ -110,7 +120,10 @@ async function request(endpointId, options = {}) {
|
||||
signal: controller.signal,
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (response.status === 401 && endpoint.auth !== false) clearAuthSession();
|
||||
if (response.status === 401 && endpoint.auth !== false) {
|
||||
clearAuthSession({ eventType: 'session-expired' });
|
||||
window.dispatchEvent(new CustomEvent('portal:auth-expired'));
|
||||
}
|
||||
const responseTraceId = payload.meta?.trace_id || response.headers.get('X-Trace-ID') || traceId;
|
||||
document.documentElement.dataset.traceId = responseTraceId;
|
||||
if (!response.ok || payload.error) {
|
||||
@@ -136,7 +149,7 @@ async function request(endpointId, options = {}) {
|
||||
else throw error;
|
||||
continue;
|
||||
}
|
||||
return { data: payload.data, meta: payload.meta || {}, traceId: responseTraceId };
|
||||
return { data: endpoint.raw ? payload : payload.data, meta: payload.meta || {}, traceId: responseTraceId };
|
||||
} catch (caught) {
|
||||
const error = caught instanceof ApiError
|
||||
? caught
|
||||
@@ -171,6 +184,10 @@ async function stream(endpointId, body, options = {}) {
|
||||
});
|
||||
if (!response.ok || !response.body) {
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (response.status === 401 && endpoint.auth !== false) {
|
||||
clearAuthSession({ eventType: 'session-expired' });
|
||||
window.dispatchEvent(new CustomEvent('portal:auth-expired'));
|
||||
}
|
||||
const detail = payload.error || {};
|
||||
throw new ApiError(detail.message || '流式请求未完成', {
|
||||
code: detail.code,
|
||||
|
||||
Reference in New Issue
Block a user