Skip to content

Commit

Permalink
feat(deploy): Improve error message when credentials are invalid. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Nov 30, 2022
1 parent ebd17cb commit 038db63
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Expand Up @@ -715,6 +715,7 @@ nexus.wait.operation = This operation may take some time. Ple
nexus.wait.repository.state = waiting for staged repository ({}) state to be one of {}
nexus.wait.repository.transitioning = repository {} is still transitioning
nexus.wait.repository.invalid.state = repository {} is not in expected state(s). Expected one of {}, actual is {}
ERROR_nexus_forbidden = Operation not authorized. Please review your credentials and try again.
ERROR_nexus_find_staging_profile = Could not find a staging profile matching {}
ERROR_nexus_create_staging_repository = Could not create a staging repository for {}
ERROR_nexus_close_repository = Could not close staging repository {}
Expand Down
Expand Up @@ -21,6 +21,7 @@
import org.jreleaser.model.internal.JReleaserContext;
import org.jreleaser.model.spi.deploy.DeployException;
import org.jreleaser.sdk.commons.AbstractMavenDeployer;
import org.jreleaser.sdk.nexus2.api.NexusAPIException;

import java.util.Set;

Expand Down Expand Up @@ -83,6 +84,12 @@ public void deploy(String name) throws DeployException {
stagingProfileId = nexus.findStagingProfileId(groupId);
} catch (Nexus2Exception e) {
context.getLogger().trace(e);
if (e.getCause() instanceof NexusAPIException) {
NexusAPIException ne = (NexusAPIException) e.getCause();
if (ne.isUnauthorized() || ne.isForbidden()) {
throw new DeployException(RB.$("ERROR_nexus_forbidden"), e);
}
}
throw new DeployException(RB.$("ERROR_nexus_find_staging_profile", groupId), e);
}

Expand Down
Expand Up @@ -35,6 +35,7 @@ public NexusAPIException(int status, String reason) {
}

public NexusAPIException(int status, String reason, Map<String, Collection<String>> headers) {
super(status + ": " + reason);
this.status = status;
this.reason = reason;
this.headers = headers;
Expand All @@ -59,4 +60,8 @@ public boolean isNotFound() {
public boolean isForbidden() {
return 403 == status;
}

public boolean isUnauthorized() {
return 401 == status;
}
}

0 comments on commit 038db63

Please sign in to comment.