Commit 76a92bf5 by Sweet Zhang

解决问题

parent 4a4af674
...@@ -11,7 +11,6 @@ interface ApiResult<T> { ...@@ -11,7 +11,6 @@ interface ApiResult<T> {
data: T data: T
} }
<<<<<<< HEAD
/** 错误分类:界面据此决定文案与是否可重试(认证类跳登录,其余可重试)。 */ /** 错误分类:界面据此决定文案与是否可重试(认证类跳登录,其余可重试)。 */
export type ApiErrorKind = 'auth' | 'timeout' | 'network' | 'server' | 'business' export type ApiErrorKind = 'auth' | 'timeout' | 'network' | 'server' | 'business'
...@@ -37,19 +36,16 @@ export class ApiError extends Error { ...@@ -37,19 +36,16 @@ export class ApiError extends Error {
} }
} }
const instance = axios.create({
baseURL: '/csf/api',
// 不加超时:后端 hang 住时页面 loading 会永久转圈
timeout: 15000
})
=======
const HEADER_MOCK_BROKER = 'X-Mock-Broker-Biz-Id' const HEADER_MOCK_BROKER = 'X-Mock-Broker-Biz-Id'
// mock-only:本地生产核对环境(.env.development.local),整条 OIDC 链路停用 // mock-only:本地生产核对环境(.env.development.local),整条 OIDC 链路停用
const mockOnly = isMockOnly const mockOnly = isMockOnly
const instance = axios.create({ baseURL: '/csf/api' }) const instance = axios.create({
>>>>>>> 0cac32e9c611857dfc32d14724490175aac1f693 baseURL: '/csf/api',
// 不加超时:后端 hang 住时页面 loading 会永久转圈
timeout: 15000
})
instance.interceptors.request.use(async (config) => { instance.interceptors.request.use(async (config) => {
// DEV 模拟身份优先于 OIDC(仅在 dev 构建中可能有值) // DEV 模拟身份优先于 OIDC(仅在 dev 构建中可能有值)
...@@ -73,17 +69,12 @@ let redirecting = false ...@@ -73,17 +69,12 @@ let redirecting = false
instance.interceptors.response.use( instance.interceptors.response.use(
(response) => response, (response) => response,
(error) => { (error) => {
<<<<<<< HEAD
const status: number | undefined = error.response?.status const status: number | undefined = error.response?.status
if (status === 401) { if (status === 401) {
if (!redirecting && window.location.pathname !== '/auth/callback') {
=======
if (error.response?.status === 401) {
// mock-only / 已选模拟身份时 401 交给页面处理,不跳 OIDC // mock-only / 已选模拟身份时 401 交给页面处理,不跳 OIDC
const mockActive = mockOnly || (import.meta.env.DEV && !!getMockBrokerBizId()) const mockActive = mockOnly || (import.meta.env.DEV && !!getMockBrokerBizId())
if (!mockActive && !redirecting && window.location.pathname !== '/auth/callback') { if (!mockActive && !redirecting && window.location.pathname !== '/auth/callback') {
>>>>>>> 0cac32e9c611857dfc32d14724490175aac1f693
redirecting = true redirecting = true
// 跳转失败(IdP 不可达)时必须复位,否则此后再也不重定向,页面卡死在错误态 // 跳转失败(IdP 不可达)时必须复位,否则此后再也不重定向,页面卡死在错误态
signinRedirect(window.location.pathname + window.location.search).catch(() => { signinRedirect(window.location.pathname + window.location.search).catch(() => {
...@@ -124,4 +115,4 @@ export async function get<T>(path: string): Promise<T> { ...@@ -124,4 +115,4 @@ export async function get<T>(path: string): Promise<T> {
export async function post<T>(path: string, body?: unknown): Promise<T> { export async function post<T>(path: string, body?: unknown): Promise<T> {
const res = await instance.post<ApiResult<T>>(path, body) const res = await instance.post<ApiResult<T>>(path, body)
return unwrap(res.data) return unwrap(res.data)
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment