Skip to content

Commit

Permalink
[RND-641] Adds QUERY_FAILURE_INDEX_NOT_FOUND as a QueryResult response (
Browse files Browse the repository at this point in the history
#298)

* Adds QUERY_FAILURE_INDEX_NOT_FOUND as a QueryResult

* Changes on elasticsearch.
  • Loading branch information
DavidJGapCR authored Sep 21, 2023
1 parent e4eb344 commit aab3e45
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function handleElasticSearchError(
if (responseException?.message.indexOf('index_not_found_exception') !== -1) {
Logger.warn(`${moduleName} ${documentProcessError} index not found`, traceId);
return {
response: 'QUERY_FAILURE_INVALID_QUERY',
response: 'QUERY_FAILURE_INDEX_NOT_FOUND',
documents: [],
failureMessage: 'IndexNotFoundException',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('When querying for documents', () => {
invalidResourceInfo.projectName = 'wrong-project';
const result = await queryDocuments(setupQueryRequest({}, {}, invalidResourceInfo), client);

expect(result.response).toEqual('QUERY_FAILURE_INVALID_QUERY');
expect(result.response).toEqual('QUERY_FAILURE_INDEX_NOT_FOUND');
expect(result.documents).toHaveLength(0);
expect(result.totalCount).toBeUndefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function handleOpenSearchError(
if (responseException?.message.indexOf('index_not_found_exception') !== -1) {
Logger.warn(`${moduleName} ${documentProcessError} index not found`, traceId);
return {
response: 'QUERY_FAILURE_INVALID_QUERY',
response: 'QUERY_FAILURE_INDEX_NOT_FOUND',
documents: [],
failureMessage: 'IndexNotFoundException',
};
Expand All @@ -65,7 +65,7 @@ export async function handleOpenSearchError(
// No object has been uploaded for the requested type
Logger.warn(`${moduleName} ${documentProcessError} index not found`, traceId);
return {
response: 'QUERY_FAILURE_INVALID_QUERY',
response: 'QUERY_FAILURE_INDEX_NOT_FOUND',
documents: [],
failureMessage: 'IndexNotFoundException',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('When querying for documents', () => {
invalidResourceInfo.projectName = 'wrong-project';
const result = await queryDocuments(setupQueryRequest({}, {}, invalidResourceInfo), client);

expect(result.response).toEqual('QUERY_FAILURE_INVALID_QUERY');
expect(result.response).toEqual('QUERY_FAILURE_INDEX_NOT_FOUND');
expect(result.documents).toHaveLength(0);
expect(result.totalCount).toBeUndefined();
});
Expand Down
12 changes: 11 additions & 1 deletion Meadowlark-js/packages/meadowlark-core/src/handler/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function query(frontendRequest: FrontendRequest): Promise<FrontendR
return { statusCode: 500, headers: frontendRequest.middleware.headerMetadata };
}

if (response === 'QUERY_FAILURE_INVALID_QUERY' && result.failureMessage !== 'IndexNotFoundException') {
if (response === 'QUERY_FAILURE_INVALID_QUERY') {
const invalidQueryHeaders = {
...frontendRequest.middleware.headerMetadata,
[TOTAL_COUNT_HEADER_NAME]: result.totalCount?.toString() ?? '0',
Expand All @@ -79,6 +79,16 @@ export async function query(frontendRequest: FrontendRequest): Promise<FrontendR
headers: invalidQueryHeaders,
};
}

if (response === 'QUERY_FAILURE_INDEX_NOT_FOUND') {
const invalidQueryHeaders = {
...frontendRequest.middleware.headerMetadata,
[TOTAL_COUNT_HEADER_NAME]: '0',
};
writeDebugStatusToLog(moduleName, frontendRequest, 'query', 200);
return { statusCode: 200, headers: invalidQueryHeaders, body: documents };
}

writeDebugStatusToLog(moduleName, frontendRequest, 'query', 200);

const headers = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
// See the LICENSE and NOTICES files in the project root for more information.

export type QueryResult = {
response: 'QUERY_SUCCESS' | 'QUERY_FAILURE_INVALID_QUERY' | 'QUERY_FAILURE_AUTHORIZATION' | 'UNKNOWN_FAILURE';
response:
| 'QUERY_SUCCESS'
| 'QUERY_FAILURE_INVALID_QUERY'
| 'QUERY_FAILURE_AUTHORIZATION'
| 'UNKNOWN_FAILURE'
| 'QUERY_FAILURE_INDEX_NOT_FOUND';
documents: Array<object>;
failureMessage?: string;
totalCount?: number;
Expand Down

0 comments on commit aab3e45

Please sign in to comment.