From c4f9dedb0928e0fb12705c1fa2f02802c26cf012 Mon Sep 17 00:00:00 2001 From: abbyhu2000 Date: Thu, 29 Aug 2024 22:07:02 +0000 Subject: [PATCH] catchign right code Signed-off-by: abbyhu2000 --- src/plugins/data/common/data_frames/types.ts | 5 +++++ .../application/view_components/utils/use_search.ts | 4 +++- .../public/search/ppl_search_interceptor.ts | 9 ++------- src/plugins/query_enhancements/server/routes/index.ts | 6 +++--- .../server/search/ppl_search_strategy.ts | 7 +++++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/plugins/data/common/data_frames/types.ts b/src/plugins/data/common/data_frames/types.ts index 978f2817bcf4..10c92e4aded3 100644 --- a/src/plugins/data/common/data_frames/types.ts +++ b/src/plugins/data/common/data_frames/types.ts @@ -105,6 +105,11 @@ export interface IDataFrameResponse extends SearchResponse { took: number; } +export interface IDataFrameResponseError { + status: number; + message: string; +} + export interface IDataFrameError extends IDataFrameResponse { error: Error; } diff --git a/src/plugins/discover/public/application/view_components/utils/use_search.ts b/src/plugins/discover/public/application/view_components/utils/use_search.ts index b6c13d4982f2..e7e72eff3ca5 100644 --- a/src/plugins/discover/public/application/view_components/utils/use_search.ts +++ b/src/plugins/discover/public/application/view_components/utils/use_search.ts @@ -226,7 +226,9 @@ export const useSearch = (services: DiscoverViewServices) => { rows: [], }); - data.search.showError(error as Error); + console.log('error', error.body); + + data.search.showError((error.body || error) as Error); } finally { initalSearchComplete.current = true; } diff --git a/src/plugins/query_enhancements/public/search/ppl_search_interceptor.ts b/src/plugins/query_enhancements/public/search/ppl_search_interceptor.ts index 4618945a35f7..c8a5165cb565 100644 --- a/src/plugins/query_enhancements/public/search/ppl_search_interceptor.ts +++ b/src/plugins/query_enhancements/public/search/ppl_search_interceptor.ts @@ -4,8 +4,7 @@ */ import { trimEnd } from 'lodash'; -import { Observable, throwError } from 'rxjs'; -import { catchError } from 'rxjs/operators'; +import { Observable } from 'rxjs'; import { formatTimePickerDate, Query } from '../../../data/common'; import { DataPublicPluginStart, @@ -52,11 +51,7 @@ export class PPLSearchInterceptor extends SearchInterceptor { const query = this.buildQuery(); - return fetch(context, query, this.getAggConfig(searchRequest, query)).pipe( - catchError((error) => { - return throwError(error); - }) - ); + return fetch(context, query, this.getAggConfig(searchRequest, query)); } public search(request: IOpenSearchDashboardsSearchRequest, options: ISearchOptions) { diff --git a/src/plugins/query_enhancements/server/routes/index.ts b/src/plugins/query_enhancements/server/routes/index.ts index 356230b317a9..60a5bed20496 100644 --- a/src/plugins/query_enhancements/server/routes/index.ts +++ b/src/plugins/query_enhancements/server/routes/index.ts @@ -15,6 +15,7 @@ import { ISearchStrategy } from '../../../data/server'; import { API, SEARCH_STRATEGY } from '../../common'; import { registerQueryAssistRoutes } from './query_assist'; import { registerDataSourceConnectionsRoutes } from './data_source_connection'; +import { instance } from '../../../console/public/application/contexts/editor_context/editor_registry'; /** * Defines a route for a specific search strategy. @@ -85,10 +86,9 @@ function defineRoute( ); return res.ok({ body: { ...queryRes } }); } catch (err) { - logger.error(err); return res.custom({ - statusCode: err.status ?? 500, - body: err, + statusCode: err.name, + body: err.message, }); } } diff --git a/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts b/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts index c6fcc262456d..e8fcbba04040 100644 --- a/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts +++ b/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts @@ -10,6 +10,7 @@ import { DATA_FRAME_TYPES, IDataFrameError, IDataFrameResponse, + IDataFrameResponseError, IDataFrameWithAggs, IOpenSearchDashboardsSearchRequest, Query, @@ -41,7 +42,9 @@ export const pplSearchStrategyProvider = ( const rawResponse: any = await pplFacet.describeQuery(context, request); if (!rawResponse.success) { - throw new Error(rawResponse.data.body); + const error = new Error(rawResponse.data.body); + error.name = rawResponse.data.status; + throw error; } const dataFrame = createDataFrame({ @@ -75,7 +78,7 @@ export const pplSearchStrategyProvider = ( took: rawResponse.took, } as IDataFrameResponse; } catch (e) { - logger.error(`pplSearchStrategy: ${e.message}`); + logger.error(`pplSearchStrategy: ${e}`); if (usage) usage.trackError(); throw e; }