From 242df37f2797039603d6607fc526bd1009c3444c Mon Sep 17 00:00:00 2001 From: SongWJ Date: Sun, 12 May 2024 18:09:47 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- STranslateDLL/LocalMode.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/STranslateDLL/LocalMode.cs b/STranslateDLL/LocalMode.cs index 4e59c1a..8cfe218 100644 --- a/STranslateDLL/LocalMode.cs +++ b/STranslateDLL/LocalMode.cs @@ -69,12 +69,15 @@ public class LocalMode } var deeplResp = JsonConvert.DeserializeObject(responseBody); + var response = new Response { - Code = resp.StatusCode.GetHashCode(), - Data = deeplResp?.Result?.Texts?.FirstOrDefault()?.Text ?? deeplResp?.Error?.Message ?? "Empty Response" + Code = resp.StatusCode.GetHashCode() }; + string defaultMessage = resp.StatusCode == System.Net.HttpStatusCode.OK ? "Empty Result" : "Empty Error Message"; + response.Data = deeplResp?.Result?.Texts?.FirstOrDefault()?.Text ?? deeplResp?.Error?.Message ?? defaultMessage; + return JsonConvert.SerializeObject(response); }