Skip to content

Commit

Permalink
trying to surface errors
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Li <lnse@amazon.com>
  • Loading branch information
sejli committed Oct 21, 2024
1 parent 6586216 commit 58f3c1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
13 changes: 11 additions & 2 deletions src/plugins/data/common/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
*/

import { i18n } from '@osd/i18n';
import { PollQueryResultsHandler, FetchStatusResponse } from '../data_frames';
import {
PollQueryResultsHandler,
FetchStatusResponse,
IDataFrameResponse,
DATA_FRAME_TYPES,
} from '../data_frames';

export interface QueryStatusOptions {
pollQueryResults: PollQueryResultsHandler;
Expand All @@ -53,11 +58,15 @@ export const handleQueryResults = async <T>(
} while (queryStatus !== 'SUCCESS' && queryStatus !== 'FAILED');

if (queryStatus === 'FAILED') {
throw new Error(
const error = Error(

Check warning on line 61 in src/plugins/data/common/utils/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/utils/helpers.ts#L61

Added line #L61 was not covered by tests
i18n.translate('data.search.request.failed', {
defaultMessage: 'An error occurred while executing the search query',
})
);
return {

Check warning on line 66 in src/plugins/data/common/utils/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/utils/helpers.ts#L66

Added line #L66 was not covered by tests
status: 'failed',
body: { error },
} as FetchStatusResponse;
}

return queryResultsRes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ export interface QueryStatus {
status: ResultStatus;
body?: {
error?: {
reason?: string;
details: string;
statusCode?: number;
message?: string;
};
statusCode?: number;
};
elapsedMs?: number;
startTime?: number;
Expand Down Expand Up @@ -154,20 +153,20 @@ export function QueryResult(props: { queryStatus: QueryStatus }) {
<div style={{ width: '250px' }}>
<EuiText size="s">
<strong>
{i18n.translate('data.query.languageService.queryResults.reasons', {
defaultMessage: `Reasons:`,
{i18n.translate('data.query.languageService.queryResults.status', {
defaultMessage: `Status:`,
})}
</strong>{' '}
{props.queryStatus.body.error.reason}
{props.queryStatus.body.error?.statusCode}
</EuiText>
<EuiText size="s">
<p>
<strong>
{i18n.translate('data.query.languageService.queryResults.details', {
defaultMessage: `Details:`,
{i18n.translate('data.query.languageService.queryResults.message', {
defaultMessage: `Message:`,
})}
</strong>{' '}
{props.queryStatus.body.error.details}
{props.queryStatus.body.error.message}
</p>
</EuiText>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ export const useSearch = (services: DiscoverViewServices) => {
}
let errorBody;
try {
errorBody = JSON.parse(error.body.message);
errorBody = JSON.parse(error.body);

Check warning on line 279 in src/plugins/discover/public/application/view_components/utils/use_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/utils/use_search.ts#L279

Added line #L279 was not covered by tests
} catch (e) {
errorBody = error.body.message;
errorBody = error.body;

Check warning on line 281 in src/plugins/discover/public/application/view_components/utils/use_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/utils/use_search.ts#L281

Added line #L281 was not covered by tests
}

data$.next({
status: ResultStatus.ERROR,
queryStatus: {
body: errorBody,
body: { error: errorBody },
elapsedMs,
},
});
Expand Down

0 comments on commit 58f3c1b

Please sign in to comment.