Skip to content

Commit

Permalink
chore(jkube-kit-config-service): removed code duplication in giving h…
Browse files Browse the repository at this point in the history
…int.
  • Loading branch information
ShivangMishra committed Sep 1, 2023
1 parent f0e0c64 commit 1f43d07
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ private interface ImageConfigurationProcessor {
void process(ImageConfiguration imageConfiguration) throws JKubeServiceException;
}

protected String getHintFromException(Exception ex) {
String message = "Error while trying to push the image: " + ex.getMessage();
if(ex.getMessage().contains("denied") || ex.getMessage().contains("unauthorized")) {
message += "\nPossible issues: invalid credentials or incorrect image name or registry." +
"\nHint: Check your credentials." +
"\nHint: Image name can be modified with the jkube.generator.name property";
}
return message;
}

private void processImage(ImageConfigurationProcessor imageConfigurationConsumer, String skipMessage, ImageConfiguration... imageConfigurations) throws JKubeServiceException {
if (imageConfigurations != null) {
for (ImageConfiguration imageConfiguration : imageConfigurations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ protected void pushSingleImage(ImageConfiguration imageConfiguration, int retrie
try {
dockerServices.getRegistryService().pushImage(imageConfiguration, retries, registryConfig, skipTag);
} catch (IOException ex) {
String message = "Error while trying to push the image: " + ex.getMessage();
if(ex.getMessage().contains("denied") || ex.getMessage().contains("unauthorized")) {
message += "\nPossible issues: invalid credentials or incorrect image name or registry." +
"\nHint: Check your credentials." +
"\nHint: Image name can be modified with the jkube.generator.name property";
}
throw new JKubeServiceException(message, ex);
throw new JKubeServiceException(getHintFromException(ex), ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,7 @@ protected void pushSingleImage(ImageConfiguration imageConfiguration, int retrie
log
);
} catch (Exception ex) {
String message = "Error while trying to push the image: " + ex.getMessage();
if(ex.getMessage().contains("denied") || ex.getMessage().contains("unauthorized")) {
message += "\nPossible issues: invalid credentials or incorrect image name or registry." +
"\nHint: Check your credentials." +
"\nHint: Image name can be modified with the jkube.generator.name property";
}
throw new JKubeServiceException(message, ex);
throw new JKubeServiceException(getHintFromException(ex), ex);
}
}

Expand Down

0 comments on commit 1f43d07

Please sign in to comment.