This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
NEXUS-4878 - Add reason to not deletable error #340
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
80df431
NEXUS-4878 - Add reason to not deletable error
velo 4dc3383
Merge branch 'master' into NEXUS-4878-improve-error
velo abedc7a
NXCM-3958 - improved error message
velo 61254df
NXCM-3958 - improved error message
velo fd03521
NEXUS-4878 - add missing RepositoryDependentException
velo f8972cc
NEXUS-4878 - using RepositoryStringUtil to display repo name
velo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../main/java/org/sonatype/nexus/configuration/application/RepositoryDependentException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.sonatype.nexus.configuration.application; | ||
|
||
import static java.lang.String.format; | ||
import static org.sonatype.nexus.proxy.utils.RepositoryStringUtils.getHumanizedNameString; | ||
|
||
import org.sonatype.configuration.ConfigurationException; | ||
import org.sonatype.nexus.proxy.repository.Repository; | ||
|
||
public class RepositoryDependentException | ||
extends ConfigurationException | ||
{ | ||
|
||
private static final long serialVersionUID = -2037859093869479166L; | ||
|
||
private final Repository dependant; | ||
|
||
private final Repository repository; | ||
|
||
public RepositoryDependentException( Repository repository, Repository dependant ) | ||
{ | ||
super( format( "Repository %s cannot be deleted due to dependency: repository %s.", | ||
getHumanizedNameString( repository ), getHumanizedNameString( dependant ) ) ); | ||
this.repository = repository; | ||
this.dependant = dependant; | ||
} | ||
|
||
public Repository getDependant() | ||
{ | ||
return dependant; | ||
} | ||
|
||
public Repository getRepository() | ||
{ | ||
return repository; | ||
} | ||
|
||
public String getUIMessage() | ||
{ | ||
return format( | ||
"Repository '%s' cannot be deleted due to dependencies on repository '%s'.\nDependencies must be removed in order to complete this operation.", | ||
getHumanizedNameString( repository ), getHumanizedNameString( dependant ) ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
import org.restlet.resource.ResourceException; | ||
import org.restlet.resource.Variant; | ||
import org.sonatype.configuration.ConfigurationException; | ||
import org.sonatype.nexus.configuration.application.RepositoryDependentException; | ||
import org.sonatype.nexus.proxy.AccessDeniedException; | ||
import org.sonatype.nexus.proxy.NoSuchRepositoryException; | ||
import org.sonatype.nexus.proxy.StorageException; | ||
|
@@ -377,12 +378,17 @@ public void delete( Context context, Request request, Response response ) | |
|
||
response.setStatus( Status.SUCCESS_NO_CONTENT ); | ||
} | ||
catch ( RepositoryDependentException e ) | ||
{ | ||
getLogger().info( e.getMessage() ); | ||
|
||
throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, e.getUIMessage(), e ); | ||
} | ||
catch ( ConfigurationException e ) | ||
{ | ||
getLogger().warn( "Repository not deletable, it has dependants, id=" + repoId ); | ||
getLogger().warn( e.getMessage() ); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps creating a more specific ConfigurationException here so in this case it can be logged as INFO? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, | ||
"Repository is not deletable, it has dependants." ); | ||
throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage(), e ); | ||
} | ||
catch ( NoSuchRepositoryAccessException e ) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this exception gets logged for administrators, I think it is important to retain the mention of the repo ID value. Both name and id wouldn't hurt though.
Suggest this should read something more like:
"Repository [id= + id + ",name=" + repository.getName() + "] + "' cannot be deleted due to dependencies: shadow repository[id=" + shadow.getId() + ",name=" +shadow.getName()+"]."