1 回答

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
只是一個(gè)關(guān)于你的,雖然你正在使用.我會(huì)這樣寫這段代碼:catchawait
import * as Msal from '@azure/msal-browser'
export async function getTokenPopup(request: Msal.TokenExchangeParameters) {
try {
return await auth.acquireTokenSilent(request);
} catch (error) {
return await auth.acquireTokenPopup(request);
}
}
const getGraphDetails = async (
uri: string,
scopes: Msal.TokenExchangeParameters,
axiosConfig?: AxiosRequestConfig
) => {
try {
const response = await getTokenPopup(scopes);
return callGraph(uri, response.accessToken, axiosConfig);
} catch (error) {
throw new Error("You could not get a token");
}
}
現(xiàn)在,為什么要進(jìn)入.有一種可能性,該函數(shù)將同時(shí)失敗, 對(duì)于 和 。因此,該函數(shù)將引發(fā)錯(cuò)誤(或不返回任何內(nèi)容,具體取決于您的實(shí)現(xiàn))。voidresponsegetTokenPopupacquireTokenSilentacquireTokenPopupgetTokenPopup
TypeScript 看到這一點(diǎn),并添加一個(gè)類型以指示有可能無法獲得響應(yīng)。void
添加回答
舉報(bào)