Skip to content

Commit c4f9ded

Browse files
committed
catchign right code
Signed-off-by: abbyhu2000 <[email protected]>
1 parent 4dc2f7e commit c4f9ded

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

src/plugins/data/common/data_frames/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export interface IDataFrameResponse extends SearchResponse<any> {
105105
took: number;
106106
}
107107

108+
export interface IDataFrameResponseError {
109+
status: number;
110+
message: string;
111+
}
112+
108113
export interface IDataFrameError extends IDataFrameResponse {
109114
error: Error;
110115
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ export const useSearch = (services: DiscoverViewServices) => {
226226
rows: [],
227227
});
228228

229-
data.search.showError(error as Error);
229+
console.log('error', error.body);
230+
231+
data.search.showError((error.body || error) as Error);
230232
} finally {
231233
initalSearchComplete.current = true;
232234
}

src/plugins/query_enhancements/public/search/ppl_search_interceptor.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
*/
55

66
import { trimEnd } from 'lodash';
7-
import { Observable, throwError } from 'rxjs';
8-
import { catchError } from 'rxjs/operators';
7+
import { Observable } from 'rxjs';
98
import { formatTimePickerDate, Query } from '../../../data/common';
109
import {
1110
DataPublicPluginStart,
@@ -52,11 +51,7 @@ export class PPLSearchInterceptor extends SearchInterceptor {
5251

5352
const query = this.buildQuery();
5453

55-
return fetch(context, query, this.getAggConfig(searchRequest, query)).pipe(
56-
catchError((error) => {
57-
return throwError(error);
58-
})
59-
);
54+
return fetch(context, query, this.getAggConfig(searchRequest, query));
6055
}
6156

6257
public search(request: IOpenSearchDashboardsSearchRequest, options: ISearchOptions) {

src/plugins/query_enhancements/server/routes/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ISearchStrategy } from '../../../data/server';
1515
import { API, SEARCH_STRATEGY } from '../../common';
1616
import { registerQueryAssistRoutes } from './query_assist';
1717
import { registerDataSourceConnectionsRoutes } from './data_source_connection';
18+
import { instance } from '../../../console/public/application/contexts/editor_context/editor_registry';
1819

1920
/**
2021
* Defines a route for a specific search strategy.
@@ -85,10 +86,9 @@ function defineRoute(
8586
);
8687
return res.ok({ body: { ...queryRes } });
8788
} catch (err) {
88-
logger.error(err);
8989
return res.custom({
90-
statusCode: err.status ?? 500,
91-
body: err,
90+
statusCode: err.name,
91+
body: err.message,
9292
});
9393
}
9494
}

src/plugins/query_enhancements/server/search/ppl_search_strategy.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
DATA_FRAME_TYPES,
1111
IDataFrameError,
1212
IDataFrameResponse,
13+
IDataFrameResponseError,
1314
IDataFrameWithAggs,
1415
IOpenSearchDashboardsSearchRequest,
1516
Query,
@@ -41,7 +42,9 @@ export const pplSearchStrategyProvider = (
4142
const rawResponse: any = await pplFacet.describeQuery(context, request);
4243

4344
if (!rawResponse.success) {
44-
throw new Error(rawResponse.data.body);
45+
const error = new Error(rawResponse.data.body);
46+
error.name = rawResponse.data.status;
47+
throw error;
4548
}
4649

4750
const dataFrame = createDataFrame({
@@ -75,7 +78,7 @@ export const pplSearchStrategyProvider = (
7578
took: rawResponse.took,
7679
} as IDataFrameResponse;
7780
} catch (e) {
78-
logger.error(`pplSearchStrategy: ${e.message}`);
81+
logger.error(`pplSearchStrategy: ${e}`);
7982
if (usage) usage.trackError();
8083
throw e;
8184
}

0 commit comments

Comments
 (0)