Skip to content

Commit

Permalink
[Bug]added error handling for api calls (#408)
Browse files Browse the repository at this point in the history
* [Bug]added error handling for api calls

Signed-off-by: sumukhswamy <[email protected]>

* linter fix

Signed-off-by: sumukhswamy <[email protected]>

---------

Signed-off-by: sumukhswamy <[email protected]>
(cherry picked from commit 853597b)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Oct 22, 2024
1 parent 0c74db3 commit 73c1a44
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 33 deletions.
130 changes: 100 additions & 30 deletions server/routes/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ 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) {
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand Down Expand Up @@ -81,9 +88,16 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {
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 @@ -103,9 +117,16 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {
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,

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

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
statusCode: retVal.data.statusCode,
});
}
}
);

Expand All @@ -125,9 +146,16 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {
const retVal = await service.describeSQLJson(context, request);

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

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
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 @@ -147,9 +175,16 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {
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 +204,16 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {
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,

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

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
});
}
}
);

Expand All @@ -191,9 +233,16 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {
const retVal = await service.describePPLText(context, request);
return response.ok({
body: retVal,
});
if (retVal.data.ok) {

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

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return response.ok({
body: retVal,
});
} else {
return response.custom({
body: retVal.data.body,
statusCode: retVal.data.statusCode,
});
}
}
);

Expand All @@ -213,9 +262,16 @@ export function registerQueryRoute(server: IRouter, service: QueryService) {
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {
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 +296,16 @@ 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 +351,16 @@ 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,

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

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
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 73c1a44

Please sign in to comment.