fix there is no error on missing revision

This commit is contained in:
Mohamed Karray
2019-03-11 18:42:10 +01:00
parent 856f564c8d
commit 77fb869ce4
3 changed files with 17 additions and 5 deletions

View File

@@ -65,6 +65,9 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
import static sonia.scm.NotFoundException.notFound;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
/** /**
@@ -128,10 +131,11 @@ public class GitBrowseCommand extends AbstractGitCommand
if (Util.isNotEmpty(request.getRevision())) if (Util.isNotEmpty(request.getRevision()))
{ {
logger.error("could not find revision {}", request.getRevision()); logger.error("could not find revision {}", request.getRevision());
throw notFound(entity("Revision", request.getRevision()).in(this.repository));
} }
else if (logger.isWarnEnabled()) else if (logger.isWarnEnabled())
{ {
logger.warn("coul not find head of repository, empty?"); logger.warn("could not find head of repository, empty?");
} }
result = new BrowserResult(Constants.HEAD, createEmtpyRoot()); result = new BrowserResult(Constants.HEAD, createEmtpyRoot());

View File

@@ -79,6 +79,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
*/ */
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(GitLogCommand.class); LoggerFactory.getLogger(GitLogCommand.class);
public static final String REVISION = "Revision";
//~--- constructors --------------------------------------------------------- //~--- constructors ---------------------------------------------------------
@@ -143,6 +144,10 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
{ {
logger.error("could not open repository", ex); logger.error("could not open repository", ex);
} }
catch (NullPointerException e)
{
throw notFound(entity(REVISION, revision).in(this.repository));
}
finally finally
{ {
IOUtil.close(converter); IOUtil.close(converter);
@@ -208,7 +213,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
if (!Strings.isNullOrEmpty(request.getAncestorChangeset())) { if (!Strings.isNullOrEmpty(request.getAncestorChangeset())) {
ancestorId = repository.resolve(request.getAncestorChangeset()); ancestorId = repository.resolve(request.getAncestorChangeset());
if (ancestorId == null) { if (ancestorId == null) {
throw notFound(entity("Revision", request.getAncestorChangeset()).in(this.repository)); throw notFound(entity(REVISION, request.getAncestorChangeset()).in(this.repository));
} }
} }
@@ -250,7 +255,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
} }
} }
} else if (ancestorId != null) { } else if (ancestorId != null) {
throw notFound(entity("Revision", request.getBranch()).in(this.repository)); throw notFound(entity(REVISION, request.getBranch()).in(this.repository));
} }
if (branch != null) { if (branch != null) {
@@ -267,7 +272,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
} }
catch (MissingObjectException e) catch (MissingObjectException e)
{ {
throw notFound(entity("Revision", e.getObjectId().getName()).in(repository)); throw notFound(entity(REVISION, e.getObjectId().getName()).in(repository));
} }
catch (NotFoundException e) catch (NotFoundException e)
{ {

View File

@@ -15,6 +15,9 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException; import java.io.IOException;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
import static sonia.scm.NotFoundException.notFound;
public class SourceRootResource { public class SourceRootResource {
private final RepositoryServiceFactory serviceFactory; private final RepositoryServiceFactory serviceFactory;
@@ -62,7 +65,7 @@ public class SourceRootResource {
if (browserResult != null) { if (browserResult != null) {
return Response.ok(browserResultToFileObjectDtoMapper.map(browserResult, namespaceAndName)).build(); return Response.ok(browserResultToFileObjectDtoMapper.map(browserResult, namespaceAndName)).build();
} else { } else {
return Response.status(Response.Status.NOT_FOUND).build(); throw notFound(entity("sources", path).in(namespaceAndName));
} }
} }
} }