Enforce trading authorization and suitability checks
This commit is contained in:
@@ -117,7 +117,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) {
|
||||
@@ -178,6 +181,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