1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-14 03:15:49 +02:00

Improve logged error message when update checking fails

This commit is contained in:
chylex 2018-06-30 13:22:37 +02:00
parent 738557b3a2
commit cfedb7d6b1

View File

@ -1,6 +1,8 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using TweetDuck.Core.Utils;
@ -28,7 +30,7 @@ public Task<UpdateInfo> Check(){
result.SetCanceled();
}
else if (task.IsFaulted){
result.SetException(task.Exception.InnerException);
result.SetException(ExpandWebException(task.Exception.InnerException));
}
else{
try{
@ -59,5 +61,20 @@ string AssetDownloadUrl(JsonObject obj){
return new UpdateInfo(versionTag, releaseNotes, downloadUrl, installerFolder);
}
private static Exception ExpandWebException(Exception e){
if (e is WebException we && we.Response is HttpWebResponse response){
try{
using(Stream stream = response.GetResponseStream())
using(StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(response.CharacterSet ?? "utf-8"))){
return new Reporter.ExpandedLogException(e, reader.ReadToEnd());
}
}catch{
// whatever
}
}
return e;
}
}
}