0

我使用 MSAL4j,并且有一个名为 MsalThrottlingException 的异常类型。抓到的时候怎么处理?我需要一个示例实现。

try{
    Future<IAuthenticationResult> future = 
    confidentialClientApplication.acquireToken(authorizationCodeParameters);
    IAuthenticationResult authenticationResult = future.get(1, TimeUnit.MINUTES); 
}
catch(ExecutionException e){
    if(e.getCause() instanceof MsalThrottlingException){
        //how to handle it
    }
}

在此处输入图像描述 https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-error-handling-java

也有关于它的文档(您可以在上面的链接中看到屏幕截图),但它没有给出处理实现的示例。你能举个例子吗?

4

1 回答 1

0

这对我有用:

    private static String PREFIX_RETRY_STR = "com.microsoft.aad.msal4j.MsalThrottlingException: Request was throttled according to instructions from STS. Retry in ";
    private static String SUFFIX_RETRY_STR = " ms.";

(...)

            if (e.getCause() instanceof MsalThrottlingException) {
                int waitTime = Integer.parseInt(e.getMessage().replace(PREFIX_RETRY_STR, "").replace(SUFFIX_RETRY_STR, ""));
                try {
                    TimeUnit.MILLISECONDS.sleep(waitTime);
                } catch (InterruptedException interruptedException) {
                    interruptedException.printStackTrace();
                }
                result = pca.acquireToken(parameters).join();
            } else
                throw e;

于 2021-06-14T21:56:51.540 回答