Skip to content

Commit

Permalink
merged error enums in a single class.
Browse files Browse the repository at this point in the history
  • Loading branch information
shenqianjin committed Sep 30, 2020
1 parent ea62350 commit d3088e7
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import com.microsoft.azuretools.authmanage.AuthMethodManager;
import com.microsoft.azuretools.authmanage.SubscriptionManager;
import com.microsoft.azuretools.authmanage.models.SubscriptionDetail;
import com.microsoft.azuretools.authmanage.srvpri.exceptions.AzureRuntimeException;
import com.microsoft.azuretools.enums.ErrorEnum;
import com.microsoft.azuretools.exception.AzureRuntimeException;
import com.microsoft.azuretools.azurecommons.helpers.AzureCmdException;
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
import com.microsoft.azuretools.enums.ErrorUIMapEnum;
import com.microsoft.azuretools.sdkmanage.AzureManager;
import com.microsoft.tooling.msservices.components.DefaultLoader;
import com.microsoft.tooling.msservices.serviceexplorer.AzureRefreshableNode;
Expand Down Expand Up @@ -123,14 +123,12 @@ private static String composeName() {
.filter(SubscriptionDetail::isSelected).collect(Collectors.toList());
return String.format("%s (%s)", BASE_MODULE_NAME, getAccountDescription(selectedSubscriptions));

} catch (AzureRuntimeException e) {
DefaultLoader.getUIHelper().showInfoNotification(
ERROR_GETTING_SUBSCRIPTIONS_TITLE, ErrorEnum.getDisplayMessageByCode(e.getCode()));
} catch (Exception e) {
if (e instanceof AzureRuntimeException) {
DefaultLoader.getUIHelper().showInfoNotification(
ERROR_GETTING_SUBSCRIPTIONS_TITLE, ErrorUIMapEnum.getViewMessageByCode(((AzureRuntimeException) e).getCode()));
} else {
final String msg = String.format(ERROR_GETTING_SUBSCRIPTIONS_MESSAGE, e.getMessage());
DefaultLoader.getUIHelper().showException(msg, e, ERROR_GETTING_SUBSCRIPTIONS_TITLE, false, true);
}
final String msg = String.format(ERROR_GETTING_SUBSCRIPTIONS_MESSAGE, e.getMessage());
DefaultLoader.getUIHelper().showException(msg, e, ERROR_GETTING_SUBSCRIPTIONS_TITLE, false, true);
}
return BASE_MODULE_NAME;
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@
* Enums of backend errors for azure tools.
*/
public enum ErrorEnum {
UNKNOWN_HOST_EXCEPTION(100000, "Encountered an unknown host exception."),
SOCKET_TIMEOUT_EXCEPTION(100002, "Encountered a socket timeout exception."),
FAILED_TO_GET_ACCESS_TOKEN_BY_CLI(100003, "Failed to get access token by Azure CLI command."),
UNKNOWN_HOST_EXCEPTION(100000, "Encountered an unknown host exception.",
"It seems you have an unstable network at the moment, please try again when network is available."),
SOCKET_TIMEOUT_EXCEPTION(100002, "Encountered a socket timeout exception.",
"Timeout when accessing azure, please try your operation again."),
FAILED_TO_GET_ACCESS_TOKEN_BY_CLI(100003, "Failed to get access token by Azure CLI command.",
"Failed to get access token, please try to login Azure CLI using 'az login' and try again."),
;

private int errorCode;
private String errorMessage;
private String displyMessage;

ErrorEnum(int errorCode, String errorMessage) {
ErrorEnum(int errorCode, String errorMessage, String displayMessage) {
this.errorCode = errorCode;
this.errorMessage = errorMessage;
this.displyMessage = displayMessage;
}

public int getErrorCode() {
Expand All @@ -47,4 +52,17 @@ public String getErrorMessage() {
return errorMessage;
}

public String getDisplyMessage() {
return displyMessage;
}

public static String getDisplayMessageByCode(int code) {
for (ErrorEnum e : ErrorEnum.values()) {
if (e.getErrorCode() == code) {
return e.getDisplyMessage();
}
}
throw new IllegalArgumentException(String.format("Not found enum for code: %s", code));
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* SOFTWARE.
*/

package com.microsoft.azuretools.authmanage.srvpri.exceptions;
package com.microsoft.azuretools.exception;

import com.microsoft.azuretools.enums.ErrorEnum;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.microsoft.azuretools.authmanage.CommonSettings;
import com.microsoft.azuretools.authmanage.Environment;
import com.microsoft.azuretools.authmanage.models.AuthMethodDetails;
import com.microsoft.azuretools.authmanage.srvpri.exceptions.AzureRuntimeException;
import com.microsoft.azuretools.exception.AzureRuntimeException;
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
import com.microsoft.azuretools.enums.ErrorEnum;
import com.microsoft.azuretools.utils.CommandUtils;
Expand Down
Loading

0 comments on commit d3088e7

Please sign in to comment.