From e523edcb05de38fe310fa6db9ea7e891cb9ead63 Mon Sep 17 00:00:00 2001 From: Uffy Date: Thu, 6 Jun 2024 11:26:33 +0800 Subject: [PATCH] feat(next/api): add translate log --- next/api/src/controller/translate.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/next/api/src/controller/translate.ts b/next/api/src/controller/translate.ts index e2ad9b62c..ca9011c5a 100644 --- a/next/api/src/controller/translate.ts +++ b/next/api/src/controller/translate.ts @@ -14,10 +14,18 @@ export class TranslateController { async translate( @Body(new ZodValidationPipe(translateSchema)) { text }: z.infer ) { - const result = await translateService.translate(text); - if (!result) { - throw new HttpError(400, 'translation service is not configured'); + const start = performance.now(); + let translateResult; + try{ + translateResult = await translateService.translate(text); + } finally { + const end = performance.now(); + console.log(`translate ${text} cost ${end - start}ms, result: ${translateResult?.from}, ${translateResult?.text}`); } - return result; + + if (!translateResult) { + throw new HttpError(400, 'translation service is not available'); + } + return translateResult; } }