From 0859353f46408b7f0f5272d7cbad4c2c28006db8 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 15 Aug 2019 10:20:59 +0200 Subject: [PATCH] use a timeout of 1s for fetching login info --- scm-ui/src/components/LoginInfo.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/scm-ui/src/components/LoginInfo.js b/scm-ui/src/components/LoginInfo.js index a7e488e646..3f7ea5ede3 100644 --- a/scm-ui/src/components/LoginInfo.js +++ b/scm-ui/src/components/LoginInfo.js @@ -31,19 +31,32 @@ class LoginInfo extends React.Component { }; } - componentDidMount() { - const { loginInfoLink } = this.props; - if (!loginInfoLink) { - return; - } - fetch(loginInfoLink) + fetchLoginInfo = (url: string) => { + return fetch(url) .then(response => response.json()) .then(info => { this.setState({ info, loading: false }); - }) + }); + }; + + timeout = (ms: number, promise: Promise) => { + return new Promise((resolve, reject) => { + setTimeout(() => { + reject(new Error("timeout during fetch of login info")); + }, ms); + promise.then(resolve, reject); + }); + }; + + componentDidMount() { + const { loginInfoLink } = this.props; + if (!loginInfoLink) { + return; + } + this.timeout(1000, this.fetchLoginInfo(loginInfoLink)) .catch(() => { this.setState({ loading: false