mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
the branch endpoint should return a not found error with context, if the branch does not exists
This commit is contained in:
@@ -79,15 +79,16 @@ public class BranchRootResource {
|
|||||||
@ResponseCode(code = 500, condition = "internal server error")
|
@ResponseCode(code = 500, condition = "internal server error")
|
||||||
})
|
})
|
||||||
public Response get(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("branch") String branchName) throws IOException {
|
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();
|
Branches branches = repositoryService.getBranchesCommand().getBranches();
|
||||||
return branches.getBranches()
|
return branches.getBranches()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(branch -> branchName.equals(branch.getName()))
|
.filter(branch -> branchName.equals(branch.getName()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(branch -> branchToDtoMapper.map(branch, new NamespaceAndName(namespace, name)))
|
.map(branch -> branchToDtoMapper.map(branch, namespaceAndName))
|
||||||
.map(Response::ok)
|
.map(Response::ok)
|
||||||
.orElse(Response.status(Response.Status.NOT_FOUND))
|
.orElseThrow(() -> notFound(entity("branch", branchName).in(namespaceAndName)))
|
||||||
.build();
|
.build();
|
||||||
} catch (CommandNotSupportedException ex) {
|
} catch (CommandNotSupportedException ex) {
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ public class BranchRootResourceTest extends RepositoryTestBase {
|
|||||||
dispatcher.invoke(request, response);
|
dispatcher.invoke(request, response);
|
||||||
|
|
||||||
assertEquals(404, response.getStatus());
|
assertEquals(404, response.getStatus());
|
||||||
|
assertEquals("application/vnd.scmm-error+json;v=2", response.getOutputHeaders().getFirst("Content-Type"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user