Skip to content

Commit

Permalink
Fix Unhandled Error Response of dev tool with MDS (#9159) (#9193)
Browse files Browse the repository at this point in the history
* Fix Unhandled Error Response of dev tool with MDS

Signed-off-by: Zhongnan Su <[email protected]>

* Changeset file for PR #9159 created/updated

---------

Signed-off-by: Zhongnan Su <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 32b0602)
  • Loading branch information
zhongnansu authored Jan 15, 2025
1 parent ece203a commit 883bd82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/9159.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fix Unhandled Error Response of dev tool with MDS ([#9159](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9159))
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { OpenSearchDashboardsRequest, RequestHandler } from 'opensearch-dashboar
import { trimStart } from 'lodash';
import { Readable } from 'stream';
import { stringify } from '@osd/std';
import { ApiResponse } from '@opensearch-project/opensearch-next';

// eslint-disable-next-line @osd/eslint/no-restricted-paths
import { ensureRawRequest } from '../../../../../../../core/server/http/router';
Expand Down Expand Up @@ -88,10 +87,6 @@ export const createHandler = ({
}: RouteDependencies): RequestHandler<unknown, Query, Body> => async (ctx, request, response) => {
const { body, query } = request;
const { path, method, dataSourceId } = query;
const client = dataSourceId
? await ctx.dataSource.opensearch.getClient(dataSourceId)
: ctx.core.opensearch.client.asCurrentUserWithLongNumeralsSupport;
let opensearchResponse: ApiResponse;

if (!pathFilters.some((re) => re.test(path))) {
return response.forbidden({
Expand All @@ -103,6 +98,10 @@ export const createHandler = ({
}

try {
const client = dataSourceId
? await ctx.dataSource.opensearch.getClient(dataSourceId)
: ctx.core.opensearch.client.asCurrentUserWithLongNumeralsSupport;

// TODO: proxy header will fail sigv4 auth type in data source, need create issue in opensearch-js repo to track
const requestHeaders = dataSourceId
? {}
Expand All @@ -111,7 +110,7 @@ export const createHandler = ({
};

const bufferedBody = await buildBufferedBody(body);
opensearchResponse = await client.transport.request(
const opensearchResponse = await client.transport.request(
{ path: toUrlPath(path), method, body: bufferedBody },
{ headers: requestHeaders }
);
Expand Down Expand Up @@ -148,7 +147,7 @@ export const createHandler = ({
});
} catch (e: any) {
const isResponseErrorFlag = isResponseError(e);
if (!isResponseError) log.error(e);
if (!isResponseErrorFlag) log.error(e);
const errorMessage = isResponseErrorFlag ? stringify(e.meta.body) : e.message;
// core http route handler has special logic that asks for stream readable input to pass error opaquely
const errorResponseBody = new Readable({
Expand All @@ -158,7 +157,7 @@ export const createHandler = ({
},
});
return response.customError({
statusCode: isResponseErrorFlag ? e.statusCode : 502,
statusCode: e.statusCode || 502,
body: errorResponseBody,
headers: {
'Content-Type': 'application/json',
Expand Down

0 comments on commit 883bd82

Please sign in to comment.