Skip to content

Commit

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



* linter fix



---------


(cherry picked from commit 853597b)

Signed-off-by: sumukhswamy <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 0c74db3 commit 1b41f0b
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>> => {
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,
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);
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,
});
}
}
);

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) {
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,
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 1b41f0b

Please sign in to comment.