Skip to content

Commit

Permalink
more specific exception block
Browse files Browse the repository at this point in the history
  • Loading branch information
Bharat Motwani committed Nov 18, 2020
1 parent 01ac903 commit 6940185
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;

import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -158,9 +160,18 @@ public static String getMD5Cksum(String cacheKey) {
MessageDigest digest = MessageDigest.getInstance("MD5");
byte[] hash = digest.digest(cacheKey.getBytes("UTF-8"));
return bytesToHex(hash); // make it readable
} catch (Exception e) {
LOG.warn("Failed to generate checksum for cache key");
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException ex) {
String msg = "Unable to initialize hash generator with default MD5 algorithm ";
LOG.warn(msg, ex);
throw new RuntimeException(msg, ex);
} catch (UnsupportedEncodingException x) {
String msg = "Unable to initialize checksum byte array ";
LOG.warn(msg, x);
throw new RuntimeException(msg, x);
} catch (Exception exception) {
String msg = "Failed to generate checksum for cache key";
LOG.warn(msg, exception);
throw new RuntimeException(msg, exception);
}
}

Expand Down

0 comments on commit 6940185

Please sign in to comment.