Skip to content

Commit

Permalink
[2.x] show error toasts if summary is disabled (#1480) (#1485)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7f363c7)

Signed-off-by: Joshua Li <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 404b7f8 commit f1574be
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 f1574be

Please sign in to comment.