微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MSAL4j - 如何处理 MsalThrottlingException?

如何解决MSAL4j - 如何处理 MsalThrottlingException?

我使用 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
    }
}

enter image description here

https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-error-handling-java

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

解决方法

这对我有用:

    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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。