6
6
using System . Net ;
7
7
using System . Net . Http ;
8
8
using System . Net . Http . Json ;
9
+ using System . Net . Sockets ;
9
10
using System . Text . Json ;
10
11
using System . Text . Json . Serialization ;
11
12
using System . Threading ;
@@ -15,6 +16,8 @@ namespace Flow.Launcher.Core.ExternalPlugins
15
16
{
16
17
public record CommunityPluginSource ( string ManifestFileUrl )
17
18
{
19
+ private static readonly string ClassName = nameof ( CommunityPluginSource ) ;
20
+
18
21
private string latestEtag = "" ;
19
22
20
23
private List < UserPlugin > plugins = new ( ) ;
@@ -34,36 +37,51 @@ public record CommunityPluginSource(string ManifestFileUrl)
34
37
/// </remarks>
35
38
public async Task < List < UserPlugin > > FetchAsync ( CancellationToken token )
36
39
{
37
- Log . Info ( nameof ( CommunityPluginSource ) , $ "Loading plugins from { ManifestFileUrl } ") ;
40
+ Log . Info ( ClassName , $ "Loading plugins from { ManifestFileUrl } ") ;
38
41
39
42
var request = new HttpRequestMessage ( HttpMethod . Get , ManifestFileUrl ) ;
40
43
41
44
request . Headers . Add ( "If-None-Match" , latestEtag ) ;
42
45
43
- using var response = await Http . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , token )
46
+ try
47
+ {
48
+ using var response = await Http . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , token )
44
49
. ConfigureAwait ( false ) ;
45
50
46
- if ( response . StatusCode == HttpStatusCode . OK )
47
- {
48
- plugins = await response . Content
49
- . ReadFromJsonAsync < List < UserPlugin > > ( PluginStoreItemSerializationOption , cancellationToken : token )
50
- . ConfigureAwait ( false ) ;
51
- latestEtag = response . Headers . ETag ? . Tag ;
51
+ if ( response . StatusCode == HttpStatusCode . OK )
52
+ {
53
+ plugins = await response . Content
54
+ . ReadFromJsonAsync < List < UserPlugin > > ( PluginStoreItemSerializationOption , cancellationToken : token )
55
+ . ConfigureAwait ( false ) ;
56
+ latestEtag = response . Headers . ETag ? . Tag ;
52
57
53
- Log . Info ( nameof ( CommunityPluginSource ) , $ "Loaded { plugins . Count } plugins from { ManifestFileUrl } ") ;
54
- return plugins ;
58
+ Log . Info ( ClassName , $ "Loaded { plugins . Count } plugins from { ManifestFileUrl } ") ;
59
+ return plugins ;
60
+ }
61
+ else if ( response . StatusCode == HttpStatusCode . NotModified )
62
+ {
63
+ Log . Info ( ClassName , $ "Resource { ManifestFileUrl } has not been modified.") ;
64
+ return plugins ;
65
+ }
66
+ else
67
+ {
68
+ Log . Warn ( ClassName ,
69
+ $ "Failed to load resource { ManifestFileUrl } with response { response . StatusCode } ") ;
70
+ return plugins ;
71
+ }
55
72
}
56
- else if ( response . StatusCode == HttpStatusCode . NotModified )
73
+ catch ( Exception e )
57
74
{
58
- Log . Info ( nameof ( CommunityPluginSource ) , $ "Resource { ManifestFileUrl } has not been modified.") ;
75
+ if ( e is HttpRequestException or WebException or SocketException || e . InnerException is TimeoutException )
76
+ {
77
+ Log . Exception ( ClassName , $ "Check your connection and proxy settings to { ManifestFileUrl } .", e ) ;
78
+ }
79
+ else
80
+ {
81
+ Log . Exception ( ClassName , "Error Occurred" , e ) ;
82
+ }
59
83
return plugins ;
60
84
}
61
- else
62
- {
63
- Log . Warn ( nameof ( CommunityPluginSource ) ,
64
- $ "Failed to load resource { ManifestFileUrl } with response { response . StatusCode } ") ;
65
- throw new Exception ( $ "Failed to load resource { ManifestFileUrl } with response { response . StatusCode } ") ;
66
- }
67
85
}
68
86
}
69
87
}
0 commit comments