diff --git a/changelog b/changelog index 6dd48076fb..18e0006329 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ MSAL Wiki : https://github.com/AzureAD/microsoft-authentication-library-for-andr vNext ---------- +-[MINOR] Add suberror for network errors (#2218) Version 5.8.2 ---------- diff --git a/common b/common index 947abe2d38..3d7fe9e660 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 947abe2d3868b1fea869f3fde689eb22d9b194f5 +Subproject commit 3d7fe9e660aed4cb8cafdb5f3041ed0618bf95d8 diff --git a/msal/src/main/java/com/microsoft/identity/client/PublicClientApplication.java b/msal/src/main/java/com/microsoft/identity/client/PublicClientApplication.java index c7dfd77272..6bc5a50725 100644 --- a/msal/src/main/java/com/microsoft/identity/client/PublicClientApplication.java +++ b/msal/src/main/java/com/microsoft/identity/client/PublicClientApplication.java @@ -1647,7 +1647,7 @@ private MsalException baseExceptionToMsalException(@NonNull final BaseException ); } - return new MsalClientException(exception.getErrorCode(), exception.getMessage()); + return MsalExceptionAdapter.msalExceptionFromBaseException(exception); } /** diff --git a/msal/src/main/java/com/microsoft/identity/client/exception/MsalUiRequiredException.java b/msal/src/main/java/com/microsoft/identity/client/exception/MsalUiRequiredException.java index 75a6cbdc86..3566bdb939 100644 --- a/msal/src/main/java/com/microsoft/identity/client/exception/MsalUiRequiredException.java +++ b/msal/src/main/java/com/microsoft/identity/client/exception/MsalUiRequiredException.java @@ -58,10 +58,9 @@ public final class MsalUiRequiredException extends MsalException { */ public static final String NO_ACCOUNT_FOUND = ErrorStrings.NO_ACCOUNT_FOUND; - @Getter - @Accessors(prefix = "m") - @Nullable - private String mOauthSubErrorCode; + public String getOauthSubErrorCode(){ + return super.getSubErrorCode(); + } /** * Constructor of MsalUiRequiredException. @@ -90,15 +89,4 @@ public MsalUiRequiredException(final String errorCode, final String errorMessage public MsalUiRequiredException(final String errorCode, final String errorMessage, final Throwable throwable) { super(errorCode, errorMessage, throwable); } - - /** - * Constructor of MsalUiRequiredException. - * @param errorCode String - * @param oauthSubErrorCode String - * @param errorMessage String - */ - public MsalUiRequiredException(final String errorCode, @Nullable final String oauthSubErrorCode, final String errorMessage) { - super(errorCode, errorMessage); - mOauthSubErrorCode = oauthSubErrorCode; - } } diff --git a/msal/src/main/java/com/microsoft/identity/client/internal/controllers/MsalExceptionAdapter.java b/msal/src/main/java/com/microsoft/identity/client/internal/controllers/MsalExceptionAdapter.java index 4dc99a55bd..b9eacb031d 100644 --- a/msal/src/main/java/com/microsoft/identity/client/internal/controllers/MsalExceptionAdapter.java +++ b/msal/src/main/java/com/microsoft/identity/client/internal/controllers/MsalExceptionAdapter.java @@ -42,6 +42,12 @@ public class MsalExceptionAdapter { public static MsalException msalExceptionFromBaseException(final BaseException e) { + final MsalException result = msalExceptionFromBaseExceptionInternal(e); + result.setSubErrorCode(e.getSubErrorCode()); + return result; + } + + private static MsalException msalExceptionFromBaseExceptionInternal(final BaseException e) { if (e instanceof MsalException) { return (MsalException) e; } @@ -69,8 +75,8 @@ public static MsalException msalExceptionFromBaseException(final BaseException e final UiRequiredException uiRequiredException = ((UiRequiredException) e); return new MsalUiRequiredException( uiRequiredException.getErrorCode(), - uiRequiredException.getOAuthSubErrorCode(), - uiRequiredException.getMessage() + uiRequiredException.getMessage(), + uiRequiredException ); } diff --git a/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/AcquireTokenMockTest.java b/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/AcquireTokenMockTest.java index 650fe1c37d..eb5df1d62b 100644 --- a/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/AcquireTokenMockTest.java +++ b/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/AcquireTokenMockTest.java @@ -118,8 +118,8 @@ public HttpResponse performIntercept( @NonNull HttpClient.HttpMethod httpMethod, @NonNull URL requestUrl, @NonNull Map requestHeaders, - @Nullable byte[] requestContent) throws IOException { - throw new IOException("Sending requests to server has been disabled for mocked unit tests"); + @Nullable byte[] requestContent) throws ClientException { + throw new ClientException("Sending requests to server has been disabled for mocked unit tests"); } }); } diff --git a/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/AcquireTokenMockedTelemetryTest.java b/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/AcquireTokenMockedTelemetryTest.java index b68f405206..91abc6c9a2 100644 --- a/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/AcquireTokenMockedTelemetryTest.java +++ b/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/AcquireTokenMockedTelemetryTest.java @@ -37,6 +37,7 @@ import com.microsoft.identity.common.java.eststelemetry.PublicApiId; import com.microsoft.identity.common.java.eststelemetry.EstsTelemetry; import com.microsoft.identity.common.java.eststelemetry.SchemaConstants; +import com.microsoft.identity.common.java.exception.ClientException; import com.microsoft.identity.common.java.net.HttpClient; import com.microsoft.identity.common.java.net.HttpResponse; import com.microsoft.identity.http.HttpRequestInterceptor; @@ -110,7 +111,7 @@ public HttpResponse performIntercept( @NonNull HttpClient.HttpMethod httpMethod, @NonNull URL requestUrl, @NonNull Map requestHeaders, - @Nullable byte[] requestContent) throws IOException { + @Nullable byte[] requestContent) throws ClientException { final String correlationId = requestHeaders.get("client-request-id"); AcquireTokenMockedTelemetryTest.addCorrelationId(correlationId); diff --git a/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/CommandResultCachingTest.java b/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/CommandResultCachingTest.java index f24d560eb3..a87d2f7e5a 100644 --- a/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/CommandResultCachingTest.java +++ b/msal/src/test/java/com/microsoft/identity/client/e2e/tests/mocked/CommandResultCachingTest.java @@ -28,6 +28,7 @@ import com.microsoft.identity.client.claims.ClaimsRequest; import com.microsoft.identity.client.e2e.shadows.ShadowMockAuthority; import com.microsoft.identity.client.e2e.shadows.ShadowOpenIdProviderConfigurationClient; +import com.microsoft.identity.common.java.exception.ClientException; import com.microsoft.identity.common.java.net.HttpClient; import com.microsoft.identity.common.java.net.HttpResponse; import com.microsoft.identity.http.HttpRequestInterceptor; @@ -83,8 +84,8 @@ public HttpResponse performIntercept( @NonNull HttpClient.HttpMethod httpMethod, @NonNull URL requestUrl, @NonNull Map requestHeaders, - @Nullable byte[] requestContent) throws IOException { - throw new IOException("Sending requests to server has been disabled for mocked unit tests"); + @Nullable byte[] requestContent) throws ClientException { + throw new ClientException("Sending requests to server has been disabled for mocked unit tests"); } });