mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Improved error handling
This commit is contained in:
parent
da53103281
commit
6d874dd1f1
@ -1,3 +1,4 @@
|
||||
import _ from 'lodash';
|
||||
import { AppNotification, AppNotificationSeverity, AppNotificationTimeout } from 'app/types';
|
||||
|
||||
const defaultSuccessNotification: AppNotification = {
|
||||
@ -31,12 +32,25 @@ export const createSuccessNotification = (title: string, text?: string): AppNoti
|
||||
id: Date.now(),
|
||||
});
|
||||
|
||||
export const createErrorNotification = (title: string, text?: string): AppNotification => ({
|
||||
...defaultErrorNotification,
|
||||
title: title,
|
||||
text: text,
|
||||
id: Date.now(),
|
||||
});
|
||||
export const createErrorNotification = (title: string, text?: any): AppNotification => {
|
||||
// Handling if text is an error object
|
||||
if (text && !_.isString(text)) {
|
||||
if (text.message) {
|
||||
text = text.message;
|
||||
} else if (text.data && text.data.message) {
|
||||
text = text.data.message;
|
||||
} else {
|
||||
text = text.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...defaultErrorNotification,
|
||||
title: title,
|
||||
text: text,
|
||||
id: Date.now(),
|
||||
};
|
||||
};
|
||||
|
||||
export const createWarningNotification = (title: string, text?: string): AppNotification => ({
|
||||
...defaultWarningNotification,
|
||||
|
@ -81,7 +81,6 @@ export function initDashboard({
|
||||
|
||||
try {
|
||||
switch (routeInfo) {
|
||||
// handle old urls with no uid
|
||||
case DashboardRouteInfo.Home: {
|
||||
// load home dash
|
||||
dashDTO = await getBackendSrv().get('/api/dashboards/home');
|
||||
@ -130,6 +129,7 @@ export function initDashboard({
|
||||
}
|
||||
} catch (err) {
|
||||
dispatch(setDashboardLoadingState(DashboardLoadingState.Error));
|
||||
dispatch(notifyApp(createErrorNotification('Dashboard fetch failed', err)));
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
@ -143,6 +143,7 @@ export function initDashboard({
|
||||
dashboard = new DashboardModel(dashDTO.dashboard, dashDTO.meta);
|
||||
} catch (err) {
|
||||
dispatch(setDashboardLoadingState(DashboardLoadingState.Error));
|
||||
dispatch(notifyApp(createErrorNotification('Dashboard model initializing failure', err)));
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
@ -168,7 +169,7 @@ export function initDashboard({
|
||||
try {
|
||||
await variableSrv.init(dashboard);
|
||||
} catch (err) {
|
||||
dispatch(notifyApp(createErrorNotification('Templating init failed')));
|
||||
dispatch(notifyApp(createErrorNotification('Templating init failed', err)));
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
@ -194,7 +195,7 @@ export function initDashboard({
|
||||
|
||||
keybindingSrv.setupDashboardBindings($scope, dashboard, onRemovePanel);
|
||||
} catch (err) {
|
||||
dispatch(notifyApp(createErrorNotification('Dashboard init failed', err.toString())));
|
||||
dispatch(notifyApp(createErrorNotification('Dashboard init failed', err)));
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user