Commit 6d874dd1 by Torkel Ödegaard

Improved error handling

parent da531032
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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment