error handling for no internet
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "capacitor-app",
|
"name": "Forum",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "An Amazing Capacitor App",
|
"description": "An Amazing Capacitor App",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ This option should be at the top level of capacitor.config.json
|
|||||||
Add "https://frm.so" to VITE_API_URL in .env.development
|
Add "https://frm.so" to VITE_API_URL in .env.development
|
||||||
|
|
||||||
### iOS: Prod Frontend and Prod Backend (frm.so)
|
### iOS: Prod Frontend and Prod Backend (frm.so)
|
||||||
Remove the "server" object from capacitor.config
|
Remove the "server" object from capacitor.config.
|
||||||
|
|
||||||
### Various Commands
|
### Various Commands
|
||||||
npx cap config - this will list the full configuration currently being used
|
npx cap config - this will list the full configuration currently being used
|
||||||
|
|||||||
@@ -9,16 +9,6 @@
|
|||||||
/>
|
/>
|
||||||
<meta name="format-detection" content="telephone=no" />
|
<meta name="format-detection" content="telephone=no" />
|
||||||
<meta name="msapplication-tap-highlight" content="no" />
|
<meta name="msapplication-tap-highlight" content="no" />
|
||||||
|
|
||||||
<script
|
|
||||||
type="module"
|
|
||||||
src="https://unpkg.com/@ionic/pwa-elements@latest/dist/ionicpwaelements/ionicpwaelements.esm.js"
|
|
||||||
></script>
|
|
||||||
<script
|
|
||||||
nomodule
|
|
||||||
src="https://unpkg.com/@ionic/pwa-elements@latest/dist/ionicpwaelements/ionicpwaelements.js"
|
|
||||||
></script>
|
|
||||||
|
|
||||||
<link rel="manifest" href="./manifest.json" />
|
<link rel="manifest" href="./manifest.json" />
|
||||||
<link rel="stylesheet" href="./_/code/shared.css" />
|
<link rel="stylesheet" href="./_/code/shared.css" />
|
||||||
<script type="module">
|
<script type="module">
|
||||||
@@ -36,8 +26,16 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
await appendScript(window.util.HOST + '/_/code/quill.js')
|
try {
|
||||||
await appendScript(window.util.HOST + '/83947261/index.js', true)
|
await appendScript(window.util.HOST + '/_/code/quill.js')
|
||||||
|
await appendScript(window.util.HOST + '/83947261/index.js', true)
|
||||||
|
} catch (e) {
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;left:0; top: 0; position: fixed; height:100vh;font-family:sans-serif;text-align:center;padding:2rem">
|
||||||
|
<p style="color: var(--text)">Could not reach the server. Are you connected to the internet?</p>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<meta name="theme-color" content="#31d53d" />
|
<meta name="theme-color" content="#31d53d" />
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
34
src/index.js
34
src/index.js
@@ -1,34 +0,0 @@
|
|||||||
import util from "./util.js"
|
|
||||||
|
|
||||||
window.__util = util
|
|
||||||
|
|
||||||
async function getProfile() {
|
|
||||||
try {
|
|
||||||
const res = await util.authFetch(`${util.HOST}/auth/profile`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: { "Accept": "application/json" }
|
|
||||||
});
|
|
||||||
if (res.status === 401) return 401;
|
|
||||||
if (!res.ok) return res.status;
|
|
||||||
return { status: 200, profile: await res.json() };
|
|
||||||
} catch {
|
|
||||||
return 500;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function init() {
|
|
||||||
await import(`${util.HOST}/shell/Shell.js`)
|
|
||||||
|
|
||||||
const result = await getProfile()
|
|
||||||
|
|
||||||
if (result === 401) {
|
|
||||||
window.AuthPage()
|
|
||||||
} else if (result === 500) {
|
|
||||||
window.ConnectionError()
|
|
||||||
} else {
|
|
||||||
window.__profile = result.profile
|
|
||||||
window.Home()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
init()
|
|
||||||
Reference in New Issue
Block a user