Skip to content

Commit

Permalink
Add error handling to refresh callback
Browse files Browse the repository at this point in the history
  • Loading branch information
estermv committed Oct 5, 2021
1 parent 723370a commit 6630572
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ export const ClusterOverview: React.FC<{}> = () => {
});

setClusters(formatClusters(response));
} catch (err) {
// TODO: handle errors
} finally {
setLoaded(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { MonitoringTimeContainer } from '../hooks/use_monitoring_time';
import { PageLoading } from '../../components';
import { getSetupModeState, isSetupModeFeatureEnabled } from '../setup_mode/setup_mode';
import { SetupModeFeature } from '../../../common/enums';
import { ajaxErrorHandlersProvider } from '../../lib/ajax_error_handler';

export interface TabMenuItem {
id: string;
Expand Down Expand Up @@ -55,7 +56,8 @@ export const PageTemplate: React.FC<PageTemplateProps> = ({

const onRefresh = () => {
getPageData?.().catch((err) => {
// TODO: handle errors
const errorHandler = ajaxErrorHandlersProvider();
errorHandler(err);
});
};

Expand Down
45 changes: 33 additions & 12 deletions x-pack/plugins/monitoring/public/lib/ajax_error_handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,43 @@ import { Legacy } from '../legacy_shims';
import { formatMsg } from '../../../../../src/plugins/kibana_legacy/public';
import { toMountPoint } from '../../../../../src/plugins/kibana_react/public';

function formatAngularErrors(err: any) {
return (
<EuiText>
<p>{err.data.message}</p>
<EuiText size="xs">
<FormattedMessage
id="xpack.monitoring.ajaxErrorHandler.httpErrorMessage"
defaultMessage="HTTP {errStatus}"
values={{ errStatus: err.status }}
/>
</EuiText>
</EuiText>
);
}

function formatReactErrors(err: any) {
return (
<EuiText>
<p>{err.body.message}</p>
<EuiText size="xs">
<FormattedMessage
id="xpack.monitoring.ajaxErrorHandler.httpErrorMessage"
defaultMessage="HTTP {errStatus}"
values={{ errStatus: err.body.statusCode }}
/>
</EuiText>
</EuiText>
);
}

export function formatMonitoringError(err: any) {
// TODO: We should stop using Boom for errors and instead write a custom handler to return richer error objects
// then we can do better messages, such as highlighting the Cluster UUID instead of requiring it be part of the message
if (err.status && err.status !== -1 && err.data) {
return (
<EuiText>
<p>{err.data.message}</p>
<EuiText size="xs">
<FormattedMessage
id="xpack.monitoring.ajaxErrorHandler.httpErrorMessage"
defaultMessage="HTTP {errStatus}"
values={{ errStatus: err.status }}
/>
</EuiText>
</EuiText>
);
return formatAngularErrors(err);
} else if (err.body) {
return formatReactErrors(err);
}

return formatMsg(err);
Expand Down

0 comments on commit 6630572

Please sign in to comment.