Skip to content

Commit

Permalink
Use .catch instead of useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
miltonhultgren committed Mar 25, 2024
1 parent bf4da37 commit 60dea26
Showing 1 changed file with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,20 @@ 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: 'Failed to initialize Observability AI Assistant',
});

setHasBeenOpened(false);
setIsOpen(false);
})
: undefined;
},
[service, hasBeenOpened]
);

useEffect(() => {
if (!chatService.error) {
return;
}

notifications.toasts.addError(chatService.error, {
title: 'Failed to initialize Observability AI Assistant',
});

setHasBeenOpened(false);
setIsOpen(false);
}, [chatService.error, notifications.toasts]);

const [isOpen, setIsOpen] = useState(false);

const keyRef = useRef(v4());
Expand Down

0 comments on commit 60dea26

Please sign in to comment.