mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 12:03:58 +00:00
error handler improved, fixes
This commit is contained in:
@@ -3,9 +3,10 @@
|
|||||||
|
|
||||||
import PluginsProvider from './plugins/PluginsProvider.svelte';
|
import PluginsProvider from './plugins/PluginsProvider.svelte';
|
||||||
import Screen from './Screen.svelte';
|
import Screen from './Screen.svelte';
|
||||||
import './utility/errorHandler';
|
import ErrorHandler from './utility/ErrorHandler.svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<ErrorHandler />
|
||||||
<PluginsProvider />
|
<PluginsProvider />
|
||||||
<CommandListener />
|
<CommandListener />
|
||||||
<Screen />
|
<Screen />
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import _ from 'lodash';
|
||||||
import FormSelectField from '../forms/FormSelectField.svelte';
|
import FormSelectField from '../forms/FormSelectField.svelte';
|
||||||
|
|
||||||
import { useConnectionList } from '../utility/metadataLoaders';
|
import { useConnectionList } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
$: connections = useConnectionList();
|
$: connections = useConnectionList();
|
||||||
$: connectionOptions = ($connections || []).map(conn => ({
|
$: connectionOptions = _.sortBy(
|
||||||
|
($connections || []).map(conn => ({
|
||||||
value: conn._id,
|
value: conn._id,
|
||||||
label: conn.displayName || conn.server,
|
label: conn.displayName || conn.server,
|
||||||
}));
|
})),
|
||||||
|
'label'
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormSelectField {...$$restProps} options={connectionOptions} />
|
<FormSelectField {...$$restProps} options={connectionOptions} />
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
import { getFormContext } from '../forms/FormProviderCore.svelte';
|
import { getFormContext } from '../forms/FormProviderCore.svelte';
|
||||||
import FormSelectField from '../forms/FormSelectField.svelte';
|
import FormSelectField from '../forms/FormSelectField.svelte';
|
||||||
import { useDatabaseList } from '../utility/metadataLoaders';
|
import { useDatabaseList } from '../utility/metadataLoaders';
|
||||||
@@ -8,10 +10,13 @@
|
|||||||
const { values } = getFormContext();
|
const { values } = getFormContext();
|
||||||
$: databases = useDatabaseList({ conid: $values[conidName] });
|
$: databases = useDatabaseList({ conid: $values[conidName] });
|
||||||
|
|
||||||
$: databaseOptions = ($databases || []).map(db => ({
|
$: databaseOptions = _.sortBy(
|
||||||
|
($databases || []).map(db => ({
|
||||||
value: db.name,
|
value: db.name,
|
||||||
label: db.name,
|
label: db.name,
|
||||||
}));
|
})),
|
||||||
|
'label'
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormSelectField {...$$restProps} options={databaseOptions} />
|
<FormSelectField {...$$restProps} options={databaseOptions} />
|
||||||
|
|||||||
46
packages/web/src/utility/ErrorHandler.svelte
Normal file
46
packages/web/src/utility/ErrorHandler.svelte
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import localforage from 'localforage';
|
||||||
|
|
||||||
|
let counter = 0;
|
||||||
|
$: counterCopy = counter;
|
||||||
|
|
||||||
|
const onunhandledrejection = async e => {
|
||||||
|
console.log('Unhandler error, checking whether crashed', e);
|
||||||
|
const oldCounter = counter;
|
||||||
|
counter++;
|
||||||
|
window.setTimeout(async () => {
|
||||||
|
if (counterCopy <= oldCounter) {
|
||||||
|
console.log('CRASH DETECTED!!!');
|
||||||
|
const lastDbGateCrashJson = localStorage.getItem('lastDbGateCrash');
|
||||||
|
const lastDbGateCrash = lastDbGateCrashJson ? JSON.parse(lastDbGateCrashJson) : null;
|
||||||
|
|
||||||
|
if (lastDbGateCrash && new Date().getTime() - lastDbGateCrash < 30 * 1000) {
|
||||||
|
if (
|
||||||
|
window.confirm(
|
||||||
|
'Sorry, DbGate has crashed again.\nDo you want to clear local user data to avoid crashing after next reload?'
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
localStorage.clear();
|
||||||
|
try {
|
||||||
|
await localforage.clear();
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error clearing app data', err);
|
||||||
|
}
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (
|
||||||
|
window.confirm(
|
||||||
|
'Sorry, DbGate has crashed.\nPress OK for reload application\nPress Cancel and inspect Console in Developer tools for error details'
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
localStorage.setItem('lastDbGateCrash', JSON.stringify(new Date().getTime()));
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window on:unhandledrejection={onunhandledrejection} />
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import localforage from 'localforage';
|
|
||||||
|
|
||||||
window.onunhandledrejection = async e => {
|
|
||||||
console.log('Unhandler error, CRASH!!!', e);
|
|
||||||
const lastDbGateCrashJson = localStorage.getItem('lastDbGateCrash');
|
|
||||||
const lastDbGateCrash = lastDbGateCrashJson ? JSON.parse(lastDbGateCrashJson) : null;
|
|
||||||
|
|
||||||
if (lastDbGateCrash && new Date().getTime() - lastDbGateCrash < 30 * 1000) {
|
|
||||||
if (
|
|
||||||
window.confirm(
|
|
||||||
'Sorry, DbGate has crashed again.\nDo you want to clear local user data to avoid crashing after next reload?'
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
localStorage.clear();
|
|
||||||
try {
|
|
||||||
await localforage.clear();
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error clearing app data', err);
|
|
||||||
}
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (window.confirm('Sorry, DbGate has crashed.\nPress OK for reload application\nPress Cancel and inspect Console in Developer tools for error details')) {
|
|
||||||
localStorage.setItem('lastDbGateCrash', JSON.stringify(new Date().getTime()));
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user