add 10 second timeout to lbrytv status call
This commit is contained in:
parent
b5bb4b46d7
commit
b005ed76fe
2 changed files with 21 additions and 1 deletions
|
@ -23,6 +23,7 @@ import useIsMobile from 'effects/use-is-mobile';
|
||||||
// @if TARGET='web'
|
// @if TARGET='web'
|
||||||
import OpenInAppLink from 'component/openInAppLink';
|
import OpenInAppLink from 'component/openInAppLink';
|
||||||
import YoutubeWelcome from 'component/youtubeWelcome';
|
import YoutubeWelcome from 'component/youtubeWelcome';
|
||||||
|
import fetchWithTimeout from 'util/fetch';
|
||||||
// @endif
|
// @endif
|
||||||
|
|
||||||
export const MAIN_WRAPPER_CLASS = 'main-wrapper';
|
export const MAIN_WRAPPER_CLASS = 'main-wrapper';
|
||||||
|
@ -251,8 +252,9 @@ function App(props: Props) {
|
||||||
}, [syncError, pathname, isAuthenticated]);
|
}, [syncError, pathname, isAuthenticated]);
|
||||||
|
|
||||||
// @if TARGET='web'
|
// @if TARGET='web'
|
||||||
|
// This should all be moved into lbrytv/component/...
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`${LBRY_TV_API}/internal/status`)
|
fetchWithTimeout(10000, fetch(`${LBRY_TV_API}/internal/status`))
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(status => {
|
.then(status => {
|
||||||
if (status.general_state !== 'ok') {
|
if (status.general_state !== 'ok') {
|
||||||
|
@ -260,6 +262,7 @@ function App(props: Props) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
console.log('err', err);
|
||||||
setCurrentlyDegradedPerformance(true);
|
setCurrentlyDegradedPerformance(true);
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
17
ui/util/fetch.js
Normal file
17
ui/util/fetch.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
export default function fetchWithTimeout(ms, promise) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const timeoutId = setTimeout(() => {
|
||||||
|
reject(new Error('promise timeout'));
|
||||||
|
}, ms);
|
||||||
|
promise.then(
|
||||||
|
res => {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
resolve(res);
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue