Skip to content

Commit

Permalink
Optimize the code
Browse files Browse the repository at this point in the history
Signed-off-by: gaobinlong <[email protected]>
  • Loading branch information
gaobinlong committed Dec 2, 2024
1 parent 63d6060 commit fcbd5d2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 21 deletions.
2 changes: 1 addition & 1 deletion server/routes/agent_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function registerAgentRoutes(router: IRouter, assistantService: Assistant
);
return res.ok({ body: response });
} catch (e) {
context.assistant_plugin.logger.debug('Execute agent failed!', e);
context.assistant_plugin.logger.error('Execute agent failed!', e);
if (e.statusCode >= 400 && e.statusCode <= 499) {
return res.customError({
body: e.body,
Expand Down
57 changes: 42 additions & 15 deletions server/routes/summary_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,20 @@ export function registerSummaryAssistantRoutes(
topNLogPatternData: req.body.topNLogPatternData,
});
} catch (e) {
return res.customError({
body: e.body || 'execute agent failed',
statusCode: e.statusCode || 500,
headers: e.headers,
});
context.assistant_plugin.logger.error('Execute agent failed!', e);
if (e.statusCode >= 400 && e.statusCode <= 499) {
return res.customError({
body: e.body,
statusCode: e.statusCode,
headers: e.headers,
});
} else {
return res.customError({
body: 'Execute agent failed!',
statusCode: 500,
headers: e.headers,
});
}
}

let summary;
Expand Down Expand Up @@ -126,11 +135,20 @@ export function registerSummaryAssistantRoutes(
question: req.body.question,
});
} catch (e) {
return res.customError({
body: e.body || 'execute agent failed',
statusCode: e.statusCode || 500,
headers: e.headers,
});
context.assistant_plugin.logger.error('Execute agent failed!', e);
if (e.statusCode >= 400 && e.statusCode <= 499) {
return res.customError({
body: e.body,
statusCode: e.statusCode,
headers: e.headers,
});
} else {
return res.customError({
body: 'Execute agent failed!',
statusCode: 500,
headers: e.headers,
});
}
}

try {
Expand Down Expand Up @@ -191,11 +209,20 @@ export function registerData2SummaryRoutes(
const result = response.body.inference_results[0].output[0].result;
return res.ok({ body: result });
} catch (e) {
return res.customError({
body: e.body || 'execute agent failed',
statusCode: e.statusCode || 500,
headers: e.headers,
});
context.assistant_plugin.logger.error('Execute agent failed!', e);
if (e.statusCode >= 400 && e.statusCode <= 499) {
return res.customError({
body: e.body,
statusCode: e.statusCode,
headers: e.headers,
});
} else {
return res.customError({
body: 'Execute agent failed!',
statusCode: 500,
headers: e.headers,
});
}
}
})
);
Expand Down
19 changes: 14 additions & 5 deletions server/routes/text2viz_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,20 @@ export function registerText2VizRoutes(router: IRouter, assistantService: Assist
const result = JSON.parse(response.body.inference_results[0].output[0].result);
return res.ok({ body: result });
} catch (e) {
return res.customError({
body: e.body || 'execute agent failed',
statusCode: e.statusCode || 500,
headers: e.headers,
});
context.assistant_plugin.logger.error('Execute agent failed!', e);
if (e.statusCode >= 400 && e.statusCode <= 499) {
return res.customError({
body: e.body,
statusCode: e.statusCode,
headers: e.headers,
});
} else {
return res.customError({
body: 'Execute agent failed!',
statusCode: 500,
headers: e.headers,
});
}
}
})
);
Expand Down

0 comments on commit fcbd5d2

Please sign in to comment.