Skip to content

Commit

Permalink
[Bug]added error handling for api calls
Browse files Browse the repository at this point in the history
Signed-off-by: sumukhswamy <[email protected]>
  • Loading branch information
sumukhswamy committed Oct 21, 2024
1 parent 8190b1f commit d002719
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 33 deletions.
140 changes: 110 additions & 30 deletions server/routes/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
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){

Check failure on line 40 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `(retVal.data.ok)` with `·(retVal.data.ok)·`
return response.ok({
body: retVal,
});
}

Check failure on line 44 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎······else` with `·else·`
else{
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode

Check failure on line 48 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
});
}
}
);

Expand Down Expand Up @@ -81,9 +89,17 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 90 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){

Check failure on line 92 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `(retVal.data.ok)` with `·(retVal.data.ok)·`
return response.ok({
body: retVal,
});
}

Check failure on line 96 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎······else` with `·else·`
else{
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode

Check failure on line 100 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
});
}
}
);

Expand All @@ -103,9 +119,17 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 120 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){

Check failure on line 122 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `(retVal.data.ok)` with `·(retVal.data.ok)·`
return response.ok({
body: retVal,
});
}

Check failure on line 126 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎······else` with `·else·`
else{
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode

Check failure on line 130 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
});
}
}
);

Expand All @@ -125,9 +149,17 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 150 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){

Check failure on line 152 in server/routes/query.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `(retVal.data.ok)` with `·(retVal.data.ok)·`
return response.ok({
body: retVal,
});
}
else{
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode
});
}
}
);

Expand All @@ -147,9 +179,17 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 180 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 @@ -169,9 +209,17 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 210 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 @@ -191,9 +239,17 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 240 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 @@ -213,9 +269,17 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {

Check warning on line 270 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 @@ -240,9 +304,17 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
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 +360,17 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
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 @@ -52,7 +52,8 @@ export default class QueryService {
data: {
ok: false,
resp: err.message,
body: err.body
body: err.body,
statusCode: err.statusCode || 400
},
};
}
Expand Down Expand Up @@ -88,7 +89,8 @@ export default class QueryService {
data: {
ok: false,
resp: err.message,
body: err.body
body: err.body,
statusCode: err.statusCode || 400
},
};
}
Expand Down Expand Up @@ -121,7 +123,8 @@ export default class QueryService {
data: {
ok: false,
resp: err.message,
body: err.body
body: err.body,
statusCode: err.statusCode || 400
},
};
}
Expand Down

0 comments on commit d002719

Please sign in to comment.