问题描述
我使用 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
也有关于它的文档(您可以在上面的链接中看到屏幕截图),但它没有给出处理实现的示例。能举个例子吗?
解决方法
这对我有用:
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;