the branch endpoint should return a not found error with context, if the branch does not exists

This commit is contained in:
Sebastian Sdorra
2019-04-03 17:10:22 +02:00
parent 3122ec5fb0
commit 7bbafee1ed
2 changed files with 5 additions and 3 deletions

View File

@@ -79,15 +79,16 @@ public class BranchRootResource {
@ResponseCode(code = 500, condition = "internal server error")
})
public Response get(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("branch") String branchName) throws IOException {
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
NamespaceAndName namespaceAndName = new NamespaceAndName(namespace, name);
try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) {
Branches branches = repositoryService.getBranchesCommand().getBranches();
return branches.getBranches()
.stream()
.filter(branch -> branchName.equals(branch.getName()))
.findFirst()
.map(branch -> branchToDtoMapper.map(branch, new NamespaceAndName(namespace, name)))
.map(branch -> branchToDtoMapper.map(branch, namespaceAndName))
.map(Response::ok)
.orElse(Response.status(Response.Status.NOT_FOUND))
.orElseThrow(() -> notFound(entity("branch", branchName).in(namespaceAndName)))
.build();
} catch (CommandNotSupportedException ex) {
return Response.status(Response.Status.BAD_REQUEST).build();

View File

@@ -129,6 +129,7 @@ public class BranchRootResourceTest extends RepositoryTestBase {
dispatcher.invoke(request, response);
assertEquals(404, response.getStatus());
assertEquals("application/vnd.scmm-error+json;v=2", response.getOutputHeaders().getFirst("Content-Type"));
}
@Test