diff --git a/scm-plugins/scm-legacy-plugin/src/main/java/sonia/scm/legacy/LegacyRepositoryService.java b/scm-plugins/scm-legacy-plugin/src/main/java/sonia/scm/legacy/LegacyRepositoryService.java index 9e27c736ea..8cac590135 100644 --- a/scm-plugins/scm-legacy-plugin/src/main/java/sonia/scm/legacy/LegacyRepositoryService.java +++ b/scm-plugins/scm-legacy-plugin/src/main/java/sonia/scm/legacy/LegacyRepositoryService.java @@ -3,6 +3,7 @@ package sonia.scm.legacy; import com.google.inject.Inject; import com.webcohesion.enunciate.metadata.rs.ResponseCode; import com.webcohesion.enunciate.metadata.rs.StatusCodes; +import sonia.scm.NotFoundException; import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryManager; @@ -33,8 +34,10 @@ public class LegacyRepositoryService { }) public NamespaceAndNameDto getNameAndNamespaceForRepositoryId(@PathParam("id") String repositoryId) { Repository repo = repositoryManager.get(repositoryId); + if (repo == null) { + throw new NotFoundException(Repository.class, repositoryId); + } return new NamespaceAndNameDto(repo.getName(), repo.getNamespace()); - } } diff --git a/scm-plugins/scm-legacy-plugin/src/main/js/index.js b/scm-plugins/scm-legacy-plugin/src/main/js/index.js index 4ddb7a0b04..22e20eced7 100644 --- a/scm-plugins/scm-legacy-plugin/src/main/js/index.js +++ b/scm-plugins/scm-legacy-plugin/src/main/js/index.js @@ -3,7 +3,12 @@ import React from "react"; import { withRouter } from "react-router-dom"; import { binder } from "@scm-manager/ui-extensions"; -import { ProtectedRoute, apiClient } from "@scm-manager/ui-components"; +import { + ProtectedRoute, + apiClient, + ErrorNotification, + ErrorBoundary +} from "@scm-manager/ui-components"; import DummyComponent from "./DummyComponent"; type Props = { @@ -13,11 +18,22 @@ type Props = { history: History }; -class LegacyRepositoryRedirect extends React.Component { - constructor(props: Props) { - super(props); +type State = { + error?: Error +}; + +class LegacyRepositoryRedirect extends React.Component { + constructor(props: Props, state: State) { + super(props, state); + this.state = { error: null }; } + handleError = (error: Error) => { + this.setState({ + error + }); + }; + redirectLegacyRepository() { const { history } = this.props; if (location.href && location.href.includes("#diffPanel;")) { @@ -25,31 +41,53 @@ class LegacyRepositoryRedirect extends React.Component { let repoId = splittedUrl[1]; let changeSetId = splittedUrl[2]; - apiClient.get("/legacy/repository/" + repoId) + apiClient + .get("/legacy/repository/" + repoId) .then(response => response.json()) - .then(payload => history.push("/repo/" + payload.namespace + "/" + payload.name + "/changesets/" + changeSetId) - ); + .then(payload => + history.push( + "/repo/" + + payload.namespace + + "/" + + payload.name + + "/changesets/" + + changeSetId + ) + ) + .catch(this.handleError); } } render() { const { authenticated } = this.props; + const { error } = this.state; + + if (error) { + return ( +
+
+ + + +
+
+ ); + } return ( <> - { - authenticated? - this.redirectLegacyRepository(): - - } + {authenticated ? ( + this.redirectLegacyRepository() + ) : ( + + )} ); } } -binder.bind("legacyRepository.redirect", withRouter(LegacyRepositoryRedirect)); - +binder.bind("legacy.redirectRepository", withRouter(LegacyRepositoryRedirect)); diff --git a/scm-ui/src/containers/Main.js b/scm-ui/src/containers/Main.js index 59cd248e07..a56f6b767c 100644 --- a/scm-ui/src/containers/Main.js +++ b/scm-ui/src/containers/Main.js @@ -9,7 +9,7 @@ import Users from "../users/containers/Users"; import Login from "../containers/Login"; import Logout from "../containers/Logout"; -import { ProtectedRoute, apiClient } from "@scm-manager/ui-components"; +import { ProtectedRoute } from "@scm-manager/ui-components"; import { binder, ExtensionPoint } from "@scm-manager/ui-extensions"; import CreateUser from "../users/containers/CreateUser"; @@ -126,7 +126,7 @@ class Main extends React.Component { authenticated={authenticated} />