diff --git a/api/jreleaser-resource-bundle/src/main/resources/org/jreleaser/bundle/Messages.properties b/api/jreleaser-resource-bundle/src/main/resources/org/jreleaser/bundle/Messages.properties index 9c48939bc..416082c14 100644 --- a/api/jreleaser-resource-bundle/src/main/resources/org/jreleaser/bundle/Messages.properties +++ b/api/jreleaser-resource-bundle/src/main/resources/org/jreleaser/bundle/Messages.properties @@ -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 {} diff --git a/sdks/jreleaser-nexus2-java-sdk/src/main/java/org/jreleaser/sdk/nexus2/Nexus2MavenDeployer.java b/sdks/jreleaser-nexus2-java-sdk/src/main/java/org/jreleaser/sdk/nexus2/Nexus2MavenDeployer.java index 83558906e..65b7cdc63 100644 --- a/sdks/jreleaser-nexus2-java-sdk/src/main/java/org/jreleaser/sdk/nexus2/Nexus2MavenDeployer.java +++ b/sdks/jreleaser-nexus2-java-sdk/src/main/java/org/jreleaser/sdk/nexus2/Nexus2MavenDeployer.java @@ -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; @@ -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); } diff --git a/sdks/jreleaser-nexus2-java-sdk/src/main/java/org/jreleaser/sdk/nexus2/api/NexusAPIException.java b/sdks/jreleaser-nexus2-java-sdk/src/main/java/org/jreleaser/sdk/nexus2/api/NexusAPIException.java index c4929b40a..97e55a4b4 100644 --- a/sdks/jreleaser-nexus2-java-sdk/src/main/java/org/jreleaser/sdk/nexus2/api/NexusAPIException.java +++ b/sdks/jreleaser-nexus2-java-sdk/src/main/java/org/jreleaser/sdk/nexus2/api/NexusAPIException.java @@ -35,6 +35,7 @@ public NexusAPIException(int status, String reason) { } public NexusAPIException(int status, String reason, Map> headers) { + super(status + ": " + reason); this.status = status; this.reason = reason; this.headers = headers; @@ -59,4 +60,8 @@ public boolean isNotFound() { public boolean isForbidden() { return 403 == status; } + + public boolean isUnauthorized() { + return 401 == status; + } }