forked from meshery/meshery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request meshery#8663 from aabidsofi19/aabidsofi/k8s-switcher
Aabidsofi/k8s switcher
- Loading branch information
Showing
5 changed files
with
68 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,40 @@ | ||
import fetch from 'isomorphic-unfetch' | ||
import fetch from "isomorphic-unfetch"; | ||
|
||
// This can be migrated as a custom hook in React | ||
const dataFetch = (url, options = {}, successFn, errorFn) => { | ||
// const controller = new AbortController(); | ||
// const signal = controller.signal; | ||
// options.signal = signal; | ||
// setTimeout(() => controller.abort(), 10000); // nice to have but will mess with the load test | ||
if (errorFn === undefined) { | ||
errorFn = (err) => { | ||
console.error(`Error fetching ${url} --DataFetch`, err); | ||
}; | ||
} | ||
fetch(url, options) | ||
.then(res => { | ||
.then((res) => { | ||
if (res.status === 401 || res.redirected) { | ||
if (window.location.host.endsWith('3000')) { | ||
window.location = '/user/login' // for local dev thru node server | ||
if (window.location.host.endsWith("3000")) { | ||
window.location = "/user/login"; // for local dev thru node server | ||
} else { | ||
window.location.reload() // for use with Go server | ||
window.location.reload(); // for use with Go server | ||
} | ||
} | ||
let result | ||
let result; | ||
if (res.ok) { | ||
// console.log(`res type: ${res.type}`); | ||
try { | ||
result = res.json() | ||
result = res.json(); | ||
} catch (e) { | ||
result = res.text() | ||
result = res.text(); | ||
} | ||
return result | ||
return result; | ||
} else { | ||
res.text().then(errorFn) | ||
res.text().then(errorFn); | ||
} | ||
}).then(successFn) | ||
.catch(errorFn) | ||
} | ||
}) | ||
.then(successFn) | ||
.catch(errorFn); | ||
}; | ||
|
||
export default dataFetch | ||
export default dataFetch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters