Skip to content

Instantly share code, notes, and snippets.

@ignu
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ignu/81ab14d8bcce8c98e191 to your computer and use it in GitHub Desktop.
Save ignu/81ab14d8bcce8c98e191 to your computer and use it in GitHub Desktop.
"snapshotshot 4"
private void handleException(Exception e) {
String[] error = e.getMessage().split("Error Code - ");
String errorMessage = error[0];
if (error.length == 2) { // error code has been supplied
int errorCode = Integer.parseInt(error[1]);
if (errorCode == 431) {
// ...
} else if (errorMessage.contains("Can't delete snapshotshot 4 due to it is not in BackedUp Status")) {
throw new EC2ServiceException(ClientError.IncorrectState, "Specified snapshot is not in the correct state 'completed' for deletion");
} else if (errorMessage.contains("Public key is invalid")) {
throw new EC2ServiceException(ClientError.InvalidKeyPair_Format, "Format of the specified key is invalid");
} else if (errorMessage.contains("Invalid resource type")) {
throw new EC2ServiceException(ClientError.InvalidParameterValue, "Specified resourceId is invalid");
} else if (errorMessage.contains("Unable to find tags by parameters specified")) {
throw new EC2ServiceException(ClientError.InvalidParameterValue, "Specified resourceTag for the specified resourceId doesn't exist");
} else if (errorMessage.contains("Failed to enable static nat for the ip address with specified ipId "
+ "as vm with specified vmId is already associated with specified currentIp")) {
throw new EC2ServiceException(ClientError.InvalidParameterValue, "Specified publicIp is already associated to the specified VM");
} else if (errorMessage.contains("Specified IP address id is not associated with any vm Id")) {
throw new EC2ServiceException(ClientError.InvalidParameterValue, "Specified publicIp is not associated to any VM");
} else if (errorMessage.contains("specify a VM that is either running or stopped")) {
throw new EC2ServiceException(ClientError.IncorrectInstanceState, "Unable to attach. Specified instances is in an incorrect state");
} else if (errorMessage.contains("specify a valid data volume")) {
throw new EC2ServiceException(ClientError.InvalidVolume_NotFound, "Specified volume doen't exist");
} else if (errorMessage.contains("VolumeId is not in Ready state, but in state Allocated. Cannot take snapshot")) {
throw new EC2ServiceException(ClientError.IncorrectState, "Cannot take snapshot. Specified volume is not in the correct state");
} else if (errorMessage.contains("Can't delete snapshot") && errorMessage.contains("it is not in BackedUp Status")) {
throw new EC2ServiceException(ClientError.IncorrectState, "Cannot delete snapshot. Specified snapshot is not in the correct state");
} else if (errorMessage.contains("Invalid port range")) {