feat: more fluent vuejs app error handler
This commit is contained in:
@@ -21,6 +21,8 @@ import {defaultConfig, plugin} from '@formkit/vue';
|
||||
import config from './formkit.config.js';
|
||||
import {TC_PULSE_EVENTS} from "@/constants/tPulseEvents.js";
|
||||
import {usePulseStore} from "@/stores/Pulse.js";
|
||||
import {TelegramInitDataError} from '@/errors.js';
|
||||
import WrongPlatformError from "@/WrongPlatformError.vue";
|
||||
|
||||
register();
|
||||
|
||||
@@ -41,7 +43,7 @@ const appLoading = createApp(AppLoading);
|
||||
appLoading.mount('#app');
|
||||
|
||||
function setTelegramUIColors() {
|
||||
const daisyUIBgColor = getCssVarOklchRgb('--color-base-100');
|
||||
const daisyUIBgColor = getCssVarOklchRgb('--color-base-200');
|
||||
window.Telegram.WebApp.setHeaderColor(daisyUIBgColor);
|
||||
window.Telegram.WebApp.setBackgroundColor(daisyUIBgColor);
|
||||
}
|
||||
@@ -56,7 +58,7 @@ settings.load()
|
||||
.then(() => settings.ya_metrika_enabled && injectYaMetrika())
|
||||
.then(() => {
|
||||
if (! window.Telegram.WebApp.initData) {
|
||||
throw new Error('Invalid init data. Application not in Telegram View');
|
||||
throw new TelegramInitDataError('Invalid init data. Application not in Telegram View');
|
||||
}
|
||||
})
|
||||
.then(() => pulse.initFromStartParams())
|
||||
@@ -113,7 +115,18 @@ settings.load()
|
||||
})
|
||||
.then(() => window.Telegram.WebApp.ready())
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
const errorApp = createApp(ApplicationError, {error});
|
||||
const code = error.code ?? error.response._data.code;
|
||||
let ErrorComponent;
|
||||
|
||||
switch (code) {
|
||||
case 'NO_INIT_DATA':
|
||||
ErrorComponent = WrongPlatformError;
|
||||
break;
|
||||
|
||||
default:
|
||||
ErrorComponent = ApplicationError;
|
||||
}
|
||||
|
||||
const errorApp = createApp(ErrorComponent, { error });
|
||||
errorApp.mount('#app-error');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user