Skip to content

Commit

Permalink
rename handleError to throwError
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 committed Dec 2, 2024
1 parent 3ff4d1d commit d181c28
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/plugins/query_enhancements/common/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { handleFacetError } from './utils';
import { throwFacetError } from './utils';

describe('handleFacetError', () => {
const error = new Error('mock-error');
Expand All @@ -16,9 +16,9 @@ describe('handleFacetError', () => {
data: error,
};

expect(() => handleFacetError(response)).toThrowError();
expect(() => throwFacetError(response)).toThrowError();
try {
handleFacetError(response);
throwFacetError(response);
} catch (err: any) {
expect(err.message).toBe('test error message');
expect(err.name).toBe('400');
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/query_enhancements/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const removeKeyword = (queryString: string | undefined) => {
return queryString?.replace(new RegExp('.keyword'), '') ?? '';
};

export const handleFacetError = (response: any) => {
export const throwFacetError = (response: any) => {
const error = new Error(response.data.body?.message ?? response.data.body ?? response.data);
error.name = response.data.status ?? response.status ?? response.data.statusCode;
(error as any).status = error.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Query,
} from '../../../data/common';
import { ISearchStrategy, SearchUsage } from '../../../data/server';
import { buildQueryStatusConfig, getFields, handleFacetError, SEARCH_STRATEGY } from '../../common';
import { buildQueryStatusConfig, getFields, throwFacetError, SEARCH_STRATEGY } from '../../common';
import { Facet } from '../utils';

export const pplAsyncSearchStrategyProvider = (
Expand Down Expand Up @@ -45,7 +45,7 @@ export const pplAsyncSearchStrategyProvider = (
request.body = { ...request.body, lang: SEARCH_STRATEGY.PPL };
const rawResponse: any = await pplAsyncFacet.describeQuery(context, request);

if (!rawResponse.success) handleFacetError(rawResponse);
if (!rawResponse.success) throwFacetError(rawResponse);

const statusConfig = buildQueryStatusConfig(rawResponse);

Expand All @@ -60,7 +60,7 @@ export const pplAsyncSearchStrategyProvider = (
request.params = { queryId: inProgressQueryId };
const queryStatusResponse = await pplAsyncJobsFacet.describeQuery(context, request);

if (!queryStatusResponse.success) handleFacetError(queryStatusResponse);
if (!queryStatusResponse.success) throwFacetError(queryStatusResponse);

const queryStatus = queryStatusResponse.data?.status;
logger.info(`pplAsyncSearchStrategy: JOB: ${inProgressQueryId} - STATUS: ${queryStatus}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Query,
createDataFrame,
} from '../../../data/common';
import { getFields, handleFacetError } from '../../common/utils';
import { getFields, throwFacetError } from '../../common/utils';
import { Facet } from '../utils';
import { QueryAggConfig } from '../../common';

Expand All @@ -39,7 +39,7 @@ export const pplSearchStrategyProvider = (
const aggConfig: QueryAggConfig | undefined = request.body.aggConfig;
const rawResponse: any = await pplFacet.describeQuery(context, request);

if (!rawResponse.success) handleFacetError(rawResponse);
if (!rawResponse.success) throwFacetError(rawResponse);

const dataFrame = createDataFrame({
name: query.dataset?.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Query,
} from '../../../data/common';
import { ISearchStrategy, SearchUsage } from '../../../data/server';
import { buildQueryStatusConfig, getFields, handleFacetError, SEARCH_STRATEGY } from '../../common';
import { buildQueryStatusConfig, getFields, throwFacetError, SEARCH_STRATEGY } from '../../common';
import { Facet } from '../utils';

export const sqlAsyncSearchStrategyProvider = (
Expand Down Expand Up @@ -45,7 +45,7 @@ export const sqlAsyncSearchStrategyProvider = (
request.body = { ...request.body, lang: SEARCH_STRATEGY.SQL };
const rawResponse: any = await sqlAsyncFacet.describeQuery(context, request);

if (!rawResponse.success) handleFacetError(rawResponse);
if (!rawResponse.success) throwFacetError(rawResponse);

const statusConfig = buildQueryStatusConfig(rawResponse);

Expand All @@ -60,7 +60,7 @@ export const sqlAsyncSearchStrategyProvider = (
request.params = { queryId: inProgressQueryId };
const queryStatusResponse = await sqlAsyncJobsFacet.describeQuery(context, request);

if (!queryStatusResponse.success) handleFacetError(queryStatusResponse);
if (!queryStatusResponse.success) throwFacetError(queryStatusResponse);

const queryStatus = queryStatusResponse.data?.status;
logger.info(`sqlAsyncSearchStrategy: JOB: ${inProgressQueryId} - STATUS: ${queryStatus}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Query,
createDataFrame,
} from '../../../data/common';
import { getFields, handleFacetError } from '../../common/utils';
import { getFields, throwFacetError } from '../../common/utils';
import { Facet } from '../utils';

export const sqlSearchStrategyProvider = (
Expand All @@ -36,7 +36,7 @@ export const sqlSearchStrategyProvider = (
const query: Query = request.body.query;
const rawResponse: any = await sqlFacet.describeQuery(context, request);

if (!rawResponse.success) handleFacetError(rawResponse);
if (!rawResponse.success) throwFacetError(rawResponse);

const dataFrame = createDataFrame({
name: query.dataset?.id,
Expand Down

0 comments on commit d181c28

Please sign in to comment.