Skip to content

Commit

Permalink
[Obs AI Assistant] Show error toast on failure (#179335)
Browse files Browse the repository at this point in the history
If the call to `ObservabilityAIAssistantAppService.start` fails, show an
error toast to notify the user.

<img width="354" alt="Screenshot 2024-03-25 at 12 23 46"
src="https://github.com/elastic/kibana/assets/2564140/021d442c-ec34-4acf-b441-6005acde1666">
  • Loading branch information
miltonhultgren authored Mar 25, 2024
1 parent 2dc44ff commit 184846c
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { EuiButton } from '@elastic/eui';
import { css } from '@emotion/react';
import { v4 } from 'uuid';
import useObservable from 'react-use/lib/useObservable';
import { i18n } from '@kbn/i18n';
import { useObservabilityAIAssistantAppService } from '../../hooks/use_observability_ai_assistant_app_service';
import { ChatFlyout } from '../chat/chat_flyout';
import { useKibana } from '../../hooks/use_kibana';
Expand All @@ -22,6 +23,7 @@ export function NavControl({}: {}) {

const {
services: {
notifications,
plugins: {
start: {
observabilityAIAssistant: { ObservabilityAIAssistantChatServiceContext },
Expand All @@ -36,7 +38,23 @@ export function NavControl({}: {}) {

const chatService = useAbortableAsync(
({ signal }) => {
return hasBeenOpened ? service.start({ signal }) : undefined;
return hasBeenOpened
? service.start({ signal }).catch((error) => {
notifications.toasts.addError(error, {
title: i18n.translate(
'xpack.observabilityAiAssistant.navControl.initFailureErrorTitle',
{
defaultMessage: 'Failed to initialize Observability AI Assistant',
}
),
});

setHasBeenOpened(false);
setIsOpen(false);

throw error;
})
: undefined;
},
[service, hasBeenOpened]
);
Expand Down

0 comments on commit 184846c

Please sign in to comment.