Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]added error handling for api calls #408

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 100 additions & 30 deletions server/routes/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 38 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const retVal = await service.describeSQLQuery(context, request);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand All @@ -57,7 +64,7 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 67 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const retVal = await service.describePPLQuery(context, request);
return response.ok({
body: retVal,
Expand All @@ -79,11 +86,18 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 89 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const retVal = await service.describeSQLCsv(context, request);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand All @@ -101,11 +115,18 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 118 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const retVal = await service.describePPLCsv(context, request);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand All @@ -123,11 +144,18 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 147 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const retVal = await service.describeSQLJson(context, request);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand All @@ -145,11 +173,18 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 176 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const retVal = await service.describePPLJson(context, request);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand All @@ -167,11 +202,18 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 205 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const retVal = await service.describeSQLText(context, request);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand All @@ -189,11 +231,18 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 234 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const retVal = await service.describePPLText(context, request);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand All @@ -211,11 +260,18 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 263 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const retVal = await service.describeSQLAsyncQuery(context, request);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand All @@ -233,16 +289,23 @@
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 292 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const retVal = await service.describeSQLAsyncGetQuery(
context,
request,
request.params.id,
request.params.dataSourceMDSId
);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand Down Expand Up @@ -288,9 +351,16 @@
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {
const retVal = await service.describeSyncQueryDataSources(context, request);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);
}
9 changes: 6 additions & 3 deletions server/services/QueryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* SPDX-License-Identifier: Apache-2.0
*/


Check failure on line 6 in server/services/QueryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `⏎`
import 'core-js/stable';
import _ from 'lodash';
import 'regenerator-runtime/runtime';
import { Logger, RequestHandlerContext } from '../../../../src/core/server';

Check failure on line 10 in server/services/QueryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `⏎`


export default class QueryService {

Check failure on line 13 in server/services/QueryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Prefer named exports
private client: any;
private dataSourceEnabled: boolean;
private logger: Logger;
Expand All @@ -21,7 +21,7 @@
this.logger = logger;
}

describeQueryPostInternal = async (request: any, format: string, responseFormat: string, body: any, context: RequestHandlerContext) => {

Check failure on line 24 in server/services/QueryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `request:·any,·format:·string,·responseFormat:·string,·body:·any,·context:·RequestHandlerContext` with `⏎····request:·any,⏎····format:·string,⏎····responseFormat:·string,⏎····body:·any,⏎····context:·RequestHandlerContext⏎··`
try {
const params = {
body: JSON.stringify(body),
Expand All @@ -30,7 +30,7 @@
let client = this.client;
let queryResponse;

const {dataSourceMDSId} = request.query;

Check failure on line 33 in server/services/QueryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `dataSourceMDSId` with `·dataSourceMDSId·`
if (this.dataSourceEnabled && dataSourceMDSId) {
client = context.dataSource.opensearch.legacy.getClient(dataSourceMDSId);
queryResponse = await client.callAPI(format, params);
Expand All @@ -52,25 +52,26 @@
data: {
ok: false,
resp: err.message,
body: err.body
body: err.body,
statusCode: err.statusCode || 400

Check failure on line 56 in server/services/QueryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
},
};
}
};

describeQueryJobIdInternal = async (request: any, format: string, jobId: string, responseFormat: string, context: any, dataSourceMDSId: string) => {

Check failure on line 62 in server/services/QueryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `request:·any,·format:·string,·jobId:·string,·responseFormat:·string,·context:·any,·dataSourceMDSId:·string` with `⏎····request:·any,⏎····format:·string,⏎····jobId:·string,⏎····responseFormat:·string,⏎····context:·any,⏎····dataSourceMDSId:·string⏎··`
try {
let client = this.client;
let queryResponse;

if (this.dataSourceEnabled && dataSourceMDSId) {

Check failure on line 68 in server/services/QueryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `⏎`
client = context.dataSource.opensearch.legacy.getClient(dataSourceMDSId);
queryResponse = await client.callAPI(format, {
jobId: jobId,

Check failure on line 71 in server/services/QueryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected property shorthand
});
} else {
queryResponse = await this.client.asScoped(request).callAsCurrentUser(format, {

Check failure on line 74 in server/services/QueryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `·`
jobId: jobId,
});
}
Expand All @@ -88,7 +89,8 @@
data: {
ok: false,
resp: err.message,
body: err.body
body: err.body,
statusCode: err.statusCode || 400
},
};
}
Expand Down Expand Up @@ -121,7 +123,8 @@
data: {
ok: false,
resp: err.message,
body: err.body
body: err.body,
statusCode: err.statusCode || 400
},
};
}
Expand Down
Loading