change exception handling in Updater and WebSearch suggestion source

This commit is contained in:
弘韬 张 2021-02-24 15:55:03 +08:00
parent 8e529c1317
commit 7739ac73fd
4 changed files with 18 additions and 17 deletions

View file

@ -87,7 +87,7 @@ namespace Flow.Launcher.Core
UpdateManager.RestartApp(Constant.ApplicationFileName);
}
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException || e is OperationCanceledException)
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException || e.InnerException is TimeoutException)
{
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"),

View file

@ -25,15 +25,16 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
const string api = "http://suggestion.baidu.com/su?json=1&wd=";
result = await Http.GetAsync(api + Uri.EscapeUriString(query), token).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
return null;
}
catch (HttpRequestException e)
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
{
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
return null;
}
catch (OperationCanceledException)
{
return null;
}
if (string.IsNullOrEmpty(result)) return new List<string>();
Match match = _reg.Match(result);
@ -44,7 +45,7 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
{
json = JsonDocument.Parse(match.Groups[1].Value);
}
catch(JsonException e)
catch (JsonException e)
{
Log.Exception("|Baidu.Suggestions|can't parse suggestions", e);
return new List<string>();

View file

@ -28,15 +28,15 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token)).RootElement.GetProperty("AS");
}
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
{
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
return null;
}
catch (OperationCanceledException)
{
return new List<string>();
}
catch (HttpRequestException e)
{
Log.Exception("|Bing.Suggestions|Can't get suggestion from Bing", e);
return new List<string>();
}
catch (JsonException e)
{
Log.Exception("|Bing.Suggestions|can't parse suggestions", e);

View file

@ -27,15 +27,15 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
json = await JsonDocument.ParseAsync(resultStream, cancellationToken: token);
}
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
{
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
return null;
}
catch (OperationCanceledException)
{
return new List<string>();
}
catch (HttpRequestException e)
{
Log.Exception("|Google.Suggestions|Can't get suggestion from google", e);
return new List<string>();
}
catch (JsonException e)
{
Log.Exception("|Google.Suggestions|can't parse suggestions", e);