mirror of
https://github.com/hansjone/netx.git
synced 2026-10-13 03:13:21 +08:00
fix(UME): 改用HTTPTransport并增强token失败提示
UME 客户端改为显式 HTTPTransport 以匹配现网可用链路,前端在手动登录/续期或断开 token 失败时优先展示后端返回的错误信息,便于快速定位问题。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
267eddb273
commit
2c0b52d972
2 changed files with 25 additions and 8 deletions
|
|
@ -175,10 +175,10 @@ class UMEClient:
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
def _client(self) -> httpx.Client:
|
def _client(self) -> httpx.Client:
|
||||||
# Force HTTP/1.1 (disable HTTP/2) due to UME server compatibility issues.
|
# Use explicit HTTPTransport to keep behavior consistent with onsite validation.
|
||||||
# httpx defaults to HTTP/1.1 unless http2=True, but some environments still
|
# In this mode, requests run over HTTP/1.1 and avoid HTTP/2 negotiation issues.
|
||||||
# negotiate/behave unexpectedly; be explicit here.
|
transport = httpx.HTTPTransport()
|
||||||
return httpx.Client(verify=self.verify_tls, timeout=self.timeout_s, http2=False)
|
return httpx.Client(verify=self.verify_tls, timeout=self.timeout_s, transport=transport)
|
||||||
|
|
||||||
def _extract_token_and_ttl(self, payload: dict[str, Any]) -> tuple[str, int | None]:
|
def _extract_token_and_ttl(self, payload: dict[str, Any]) -> tuple[str, int | None]:
|
||||||
token = ""
|
token = ""
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ function toIsoNoMs(d: Date): string {
|
||||||
|
|
||||||
export function UmePage() {
|
export function UmePage() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const [tokenOpError, setTokenOpError] = useState("");
|
||||||
const [syncPage, setSyncPage] = useState(1);
|
const [syncPage, setSyncPage] = useState(1);
|
||||||
const [syncPageSize, setSyncPageSize] = useState(20);
|
const [syncPageSize, setSyncPageSize] = useState(20);
|
||||||
const [neKeyword, setNeKeyword] = useState("");
|
const [neKeyword, setNeKeyword] = useState("");
|
||||||
|
|
@ -71,15 +72,31 @@ export function UmePage() {
|
||||||
});
|
});
|
||||||
const tokenRefreshMutation = useMutation({
|
const tokenRefreshMutation = useMutation({
|
||||||
mutationFn: refreshUmeToken,
|
mutationFn: refreshUmeToken,
|
||||||
onSuccess: async () => {
|
onSuccess: async (res) => {
|
||||||
|
if (!res?.ok) {
|
||||||
|
setTokenOpError(String(res.error || res.error_kind || "token_refresh_failed"));
|
||||||
|
} else {
|
||||||
|
setTokenOpError("");
|
||||||
|
}
|
||||||
await queryClient.invalidateQueries({ queryKey: ["umeTokenStatus"] });
|
await queryClient.invalidateQueries({ queryKey: ["umeTokenStatus"] });
|
||||||
},
|
},
|
||||||
|
onError: (err) => {
|
||||||
|
setTokenOpError(String(err));
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const tokenDisconnectMutation = useMutation({
|
const tokenDisconnectMutation = useMutation({
|
||||||
mutationFn: disconnectUmeToken,
|
mutationFn: disconnectUmeToken,
|
||||||
onSuccess: async () => {
|
onSuccess: async (res) => {
|
||||||
|
if (!res?.ok) {
|
||||||
|
setTokenOpError(String(res.error || res.error_kind || "token_disconnect_failed"));
|
||||||
|
} else {
|
||||||
|
setTokenOpError("");
|
||||||
|
}
|
||||||
await queryClient.invalidateQueries({ queryKey: ["umeTokenStatus"] });
|
await queryClient.invalidateQueries({ queryKey: ["umeTokenStatus"] });
|
||||||
},
|
},
|
||||||
|
onError: (err) => {
|
||||||
|
setTokenOpError(String(err));
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const tokenExpiresIn = Number(tokenStatusQuery.data?.expires_in_s || 0);
|
const tokenExpiresIn = Number(tokenStatusQuery.data?.expires_in_s || 0);
|
||||||
|
|
@ -151,9 +168,9 @@ export function UmePage() {
|
||||||
断开 token
|
断开 token
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{(tokenRefreshMutation.error || tokenDisconnectMutation.error) && (
|
{(tokenOpError || tokenRefreshMutation.error || tokenDisconnectMutation.error) && (
|
||||||
<div className="pill pill--high">
|
<div className="pill pill--high">
|
||||||
操作失败: {String(tokenRefreshMutation.error || tokenDisconnectMutation.error)}
|
操作失败: {tokenOpError || String(tokenRefreshMutation.error || tokenDisconnectMutation.error)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</article>
|
</article>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue