Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const SamplePreviewTableContent = ({
}

if ((value && value.status === 'failure') || error) {
const formattedError = getFormattedError(error);
const formattedError = error && getFormattedError(error);
return (
<EuiCallOut
color="danger"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useStreamsAppFetch } from '../../../hooks/use_streams_app_fetch';
import { useKibana } from '../../../hooks/use_kibana';
import { SchemaField, isSchemaFieldTyped } from '../types';
import { convertToFieldDefinitionConfig } from '../utils';
import { getFormattedError } from '../../../util/errors';

export const useSchemaFields = ({
definition,
Expand Down Expand Up @@ -143,7 +144,7 @@ export const useSchemaFields = ({
defaultMessage: 'Something went wrong editing the {field} field',
values: { field: field.name },
}),
toastMessage: error.body.message,
toastMessage: getFormattedError(error).message,
toastLifeTimeMs: 5000,
});
}
Expand Down Expand Up @@ -191,7 +192,7 @@ export const useSchemaFields = ({
defaultMessage: 'Something went wrong unmapping the {field} field',
values: { field: fieldName },
}),
toastMessage: error.message,
toastMessage: getFormattedError(error).message,
toastLifeTimeMs: 5000,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useKibana } from '../../hooks/use_kibana';
import { EditLifecycleModal, LifecycleEditAction } from './modal';
import { RetentionSummary } from './summary';
import { RetentionMetadata } from './metadata';
import { getFormattedError } from '../../util/errors';

function useLifecycleState({
definition,
Expand Down Expand Up @@ -156,7 +157,7 @@ export function StreamDetailLifecycle({
title: i18n.translate('xpack.streams.streamDetailLifecycle.failed', {
defaultMessage: 'Failed to update lifecycle',
}),
toastMessage: 'body' in error ? error.body.message : error.message,
toastMessage: getFormattedError(error).message,
});
} finally {
setUpdateInProgress(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { useBoolean } from '@kbn/react-hooks';
import useToggle from 'react-use/lib/useToggle';
import { useStreamsAppRouter } from '../../hooks/use_streams_app_router';
import { useWiredStreams } from '../../hooks/use_wired_streams';
import { getFormattedError } from '../../util/errors';

export type LifecycleEditAction = 'none' | 'dsl' | 'ilm' | 'inherit';

Expand Down Expand Up @@ -297,7 +298,7 @@ function IlmModal({
setPolicies(policyOptions);
})
.catch((error) => {
setErrorMessage('body' in error ? error.body.message : error.message);
setErrorMessage(getFormattedError(error).message);
})
.finally(() => setIsLoading(false));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useKibana } from '../../hooks/use_kibana';
import { useStreamsAppRouter } from '../../hooks/use_streams_app_router';
import { emptyEqualsToAlways } from '../../util/condition';
import { useRoutingState } from './hooks/routing_state';
import { getFormattedError } from '../../util/errors';

export function ControlBar({
definition,
Expand Down Expand Up @@ -158,7 +159,7 @@ export function ControlBar({
title: i18n.translate('xpack.streams.failedToSave', {
defaultMessage: 'Failed to save',
}),
toastMessage: 'body' in error ? error.body.message : error.message,
toastMessage: getFormattedError(error).message,
});
routingAppState.setLastDisplayedToast(toast);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

export const getFormattedError = (error?: Error) => {
export const getFormattedError = (error: Error) => {
if (
error &&
'body' in error &&
Expand All @@ -16,4 +16,5 @@ export const getFormattedError = (error?: Error) => {
) {
return new Error(error.body.message);
}
return error;
};