Skip to content

Commit

Permalink
show error toasts if summary is disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 committed Mar 4, 2024
1 parent e9690a6 commit 786ac1d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('<QueryAssistInput /> spec', () => {
);
});

it('should not call summarize if disabled', async () => {
it('should call add error toast if summarize is disabled', async () => {
coreRefs.summarizeEnabled = false;
httpMock.post.mockRejectedValueOnce({ body: { statusCode: 429 } });

Expand All @@ -98,6 +98,13 @@ describe('<QueryAssistInput /> spec', () => {
body: '{"question":"test-input","index":"selected-test-index"}',
});
expect(httpMock.post).not.toBeCalledWith(QUERY_ASSIST_API.SUMMARIZE, expect.anything());
expect(coreRefs.toasts?.addError).toBeCalledWith(
{
message: 'Request is throttled. Try again later or contact your administrator',
statusCode: 429,
},
{ title: 'Failed to generate results' }
);
});

it('should call summarize for generate and run errors', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,13 @@ export const QueryAssistInput: React.FC<Props> = (props) => {
await props.handleTimePickerChange([QUERY_ASSIST_START_TIME, 'now']);
await props.handleTimeRangePickerRefresh(undefined, true);
} catch (error) {
generateSummary({ isError: true, response: JSON.stringify((error as ResponseError).body) });
if (coreRefs.summarizeEnabled) {
generateSummary({ isError: true, response: JSON.stringify((error as ResponseError).body) });
} else {
coreRefs.toasts?.addError(formatError(error as ResponseError), {
title: 'Failed to generate results',
});
}
} finally {
setGeneratingOrRunning(false);
}
Expand Down

0 comments on commit 786ac1d

Please sign in to comment.