2 Commits

Author SHA1 Message Date
bdd4424f44 接口请求返回登录页后不再重定向 2026-06-17 14:00:09 +08:00
dfaf39e37e 修复跳转异常拦截问题 2026-06-17 13:34:48 +08:00

View File

@@ -1,6 +1,7 @@
'use server' 'use server'
import {API_BASE_URL, ApiResponse, CLIENT_ID, CLIENT_SECRET} from '@/lib/api' import {API_BASE_URL, ApiResponse, CLIENT_ID, CLIENT_SECRET} from '@/lib/api'
import {add, isBefore} from 'date-fns' import {add, isBefore} from 'date-fns'
import {isRedirectError} from 'next/dist/client/components/redirect-error'
import {cookies, headers} from 'next/headers' import {cookies, headers} from 'next/headers'
import {redirect} from 'next/navigation' import {redirect} from 'next/navigation'
import {cache} from 'react' import {cache} from 'react'
@@ -125,7 +126,7 @@ async function call<R = undefined>(url: string, body: RequestInit['body'], auth?
}) })
if (response.status === 401) { if (response.status === 401) {
return redirect('/login?redirect=' + encodeURIComponent(url.replace(API_BASE_URL, ''))) return redirect('/login')
} }
const type = response.headers.get('Content-Type') ?? 'text/plain' const type = response.headers.get('Content-Type') ?? 'text/plain'
@@ -169,6 +170,9 @@ async function call<R = undefined>(url: string, body: RequestInit['body'], auth?
} }
catch (e) { catch (e) {
console.error('后端请求失败', url, (e as Error).message) console.error('后端请求失败', url, (e as Error).message)
if (isRedirectError(e)) {
throw e
}
throw new Error(`请求失败,网络错误`) throw new Error(`请求失败,网络错误`)
} }
} }