diff --git a/scm-ui/public/locales/de/repos.json b/scm-ui/public/locales/de/repos.json index 6170c9021f..6f7846df72 100644 --- a/scm-ui/public/locales/de/repos.json +++ b/scm-ui/public/locales/de/repos.json @@ -44,8 +44,6 @@ "subtitle": "Erstellen eines neuen Repository" }, "branches": { - "errorTitle": "Fehler", - "errorSubtitle": "Unbekannter Branch Fehler", "overview": { "title": "Übersicht aller verfügbaren Branches", "createButton": "Branch erstellen" diff --git a/scm-ui/public/locales/en/repos.json b/scm-ui/public/locales/en/repos.json index ad59f2b5e0..9825298f7a 100644 --- a/scm-ui/public/locales/en/repos.json +++ b/scm-ui/public/locales/en/repos.json @@ -47,8 +47,6 @@ "subtitle": "Create a new repository" }, "branches": { - "errorTitle": "Error", - "errorSubtitle": "Unknown branch error", "overview": { "title": "Overview of all branches", "createButton": "Create Branch" diff --git a/scm-ui/src/repos/branches/containers/BranchRoot.js b/scm-ui/src/repos/branches/containers/BranchRoot.js index f1570735e2..2e9fb10f73 100644 --- a/scm-ui/src/repos/branches/containers/BranchRoot.js +++ b/scm-ui/src/repos/branches/containers/BranchRoot.js @@ -3,7 +3,6 @@ import React from "react"; import BranchView from "../components/BranchView"; import { connect } from "react-redux"; import { Redirect, Route, Switch, withRouter } from "react-router-dom"; -import { translate } from "react-i18next"; import type { Repository, Branch } from "@scm-manager/ui-types"; import { fetchBranch, @@ -11,8 +10,9 @@ import { getFetchBranchFailure, isFetchBranchPending } from "../modules/branches"; -import { ErrorPage, Loading } from "@scm-manager/ui-components"; +import { ErrorNotification, Loading } from "@scm-manager/ui-components"; import type { History } from "history"; +import { NotFoundError } from "@scm-manager/ui-components"; type Props = { repository: Repository, @@ -22,7 +22,6 @@ type Props = { error?: Error, // context props - t: string => string, history: History, match: any, location: any, @@ -55,7 +54,6 @@ class BranchRoot extends React.Component { branch, loading, error, - t, match, location } = this.props; @@ -63,16 +61,12 @@ class BranchRoot extends React.Component { const url = this.matchedUrl(); if (error) { - if(location.search.indexOf("?create=true") > -1) { + if(error instanceof NotFoundError && location.search.indexOf("?create=true") > -1) { return ; } return ( - + ); } @@ -121,5 +115,5 @@ export default withRouter( connect( mapStateToProps, mapDispatchToProps - )(translate("repos")(BranchRoot)) + )(BranchRoot) ); diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java index f0edbf79fb..9e7353b4b7 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java @@ -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(); diff --git a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/BranchRootResourceTest.java b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/BranchRootResourceTest.java index 9fb20c0922..2c83d5e3e1 100644 --- a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/BranchRootResourceTest.java +++ b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/BranchRootResourceTest.java @@ -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