fix: catch not connect to network exception

master
ZGGSONG 2 years ago
parent d94b20f39b
commit 866d896df8

@ -60,6 +60,8 @@ namespace STranslate.Utils
public static async Task<string> GetAsync(string urlpath)
{
using (var client = new HttpClient())
{
try
{
var respContent = await client.GetAsync(urlpath);
@ -67,6 +69,11 @@ namespace STranslate.Utils
return respStr;
}
catch (Exception ex)
{
throw ex;
}
}
}
}
}

@ -60,6 +60,8 @@ namespace STranslate.Utils
/// <param name="source">当前语言</param>
/// <returns></returns>
public static async Task<string> TranslateBaiduAsync(string appID, string secretKey, string text, LanguageEnum target, LanguageEnum source = LanguageEnum.AUTO)
{
try
{
Random rd = new Random();
string salt = rd.Next(100000).ToString();
@ -93,6 +95,11 @@ namespace STranslate.Utils
}
return string.Empty;
}
catch (Exception ex)
{
throw ex;
}
}
// 计算MD5值
public static string EncryptString(string str)
{

@ -18,8 +18,6 @@ namespace STranslate.ViewModel
private string Text;
public MainVM()
{
try
{
//初始化界面参数
InputCombo = LanguageEnumDict.Keys.ToList();
@ -44,6 +42,8 @@ namespace STranslate.ViewModel
{
return string.IsNullOrEmpty(InputTxt) ? false : true;
}, async (_) =>
{
try
{
Text = InputTxt;
@ -63,14 +63,12 @@ namespace STranslate.ViewModel
return;
}
OutputTxt = translateResp;
Clipboard.SetText(OutputTxt);
});
}
catch (Exception ex)
{
OutputTxt = ex.Message;
}
});
}
public ICommand TranslateCmd { get; private set; }