Skip to content

Commit

Permalink
adding new error for error state
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 23, 2024
1 parent 65c1e78 commit b7ab03f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/plugins/query_enhancements/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
export * from './constants';
export * from './types';
export * from './utils';
export * from './errors';
8 changes: 7 additions & 1 deletion src/plugins/query_enhancements/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ export function defineSearchStrategyRouteProvider(logger: Logger, router: IRoute
const queryRes: IDataFrameResponse = await searchStrategy.search(context, req as any, {});
return res.ok({ body: { ...queryRes } });
} catch (err) {
let error;
try {
error = JSON.parse(err.message);
} catch (e) {
error = err;
}
return res.custom({
statusCode: err.name,
statusCode: error.status,
body: err.message,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import {
createDataFrame,
} from '../../../data/common';
import { Facet } from '../utils';
import { buildQueryStatusConfig, getFields, handleFacetError, SEARCH_STRATEGY } from '../../common';
import {
buildQueryStatusConfig,
getFields,
handleFacetError,
SEARCH_STRATEGY,
PollingResponseError,
} from '../../common';

export const sqlAsyncSearchStrategyProvider = (
config$: Observable<SharedGlobalConfig>,
Expand Down Expand Up @@ -78,13 +84,8 @@ export const sqlAsyncSearchStrategyProvider = (
body: dataFrame,
} as IDataFrameResponse;
} else if (queryStatus?.toUpperCase() === 'FAILED') {
return {
type: DATA_FRAME_TYPES.POLLING,
status: 'failed',
body: {
error: new Error(`JOB: ${pollQueryResultsParams.queryId} failed`),
},
} as IDataFrameResponse;
const error = new PollingResponseError(queryStatusResponse.data.error, 500);
throw error;
}

return {
Expand Down

0 comments on commit b7ab03f

Please sign in to comment.