Skip to content

Commit 7739ac7

Browse files
committed
change exception handling in Updater and WebSearch suggestion source
1 parent 8e529c1 commit 7739ac7

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

Flow.Launcher.Core/Updater.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
8787
UpdateManager.RestartApp(Constant.ApplicationFileName);
8888
}
8989
}
90-
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException || e is OperationCanceledException)
90+
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException || e.InnerException is TimeoutException)
9191
{
9292
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
9393
api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"),

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
2525
const string api = "http://suggestion.baidu.com/su?json=1&wd=";
2626
result = await Http.GetAsync(api + Uri.EscapeUriString(query), token).ConfigureAwait(false);
2727
}
28-
catch (OperationCanceledException)
28+
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
2929
{
30+
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
3031
return null;
3132
}
32-
catch (HttpRequestException e)
33+
catch (OperationCanceledException)
3334
{
34-
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
3535
return null;
3636
}
3737

38+
3839
if (string.IsNullOrEmpty(result)) return new List<string>();
3940
Match match = _reg.Match(result);
4041
if (match.Success)
@@ -44,7 +45,7 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
4445
{
4546
json = JsonDocument.Parse(match.Groups[1].Value);
4647
}
47-
catch(JsonException e)
48+
catch (JsonException e)
4849
{
4950
Log.Exception("|Baidu.Suggestions|can't parse suggestions", e);
5051
return new List<string>();

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
2828
json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token)).RootElement.GetProperty("AS");
2929

3030
}
31-
catch (OperationCanceledException)
31+
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
3232
{
33-
return new List<string>();
33+
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
34+
return null;
3435
}
35-
catch (HttpRequestException e)
36+
catch (OperationCanceledException)
3637
{
37-
Log.Exception("|Bing.Suggestions|Can't get suggestion from Bing", e);
3838
return new List<string>();
3939
}
4040
catch (JsonException e)

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
2727
json = await JsonDocument.ParseAsync(resultStream, cancellationToken: token);
2828

2929
}
30-
catch (OperationCanceledException)
30+
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
3131
{
32-
return new List<string>();
32+
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
33+
return null;
3334
}
34-
catch (HttpRequestException e)
35+
catch (OperationCanceledException)
3536
{
36-
Log.Exception("|Google.Suggestions|Can't get suggestion from google", e);
3737
return new List<string>();
3838
}
3939
catch (JsonException e)

0 commit comments

Comments
 (0)