feat(plugin): handle errors nicely
This commit is contained in:
parent
4d7f0599f3
commit
58eec899b4
|
@ -82,11 +82,11 @@ public class Plugin : IDalamudPlugin {
|
|||
});
|
||||
|
||||
Task.Run(async () => {
|
||||
var mem = new MemoryStream();
|
||||
var gz = new GZipStream(mem, CompressionLevel.Optimal);
|
||||
await gz.WriteAsync(Encoding.UTF8.GetBytes(json));
|
||||
await gz.FlushAsync();
|
||||
await gz.DisposeAsync();
|
||||
using var mem = new MemoryStream();
|
||||
await using (var gz = new GZipStream(mem, CompressionLevel.Optimal)) {
|
||||
await gz.WriteAsync(Encoding.UTF8.GetBytes(json));
|
||||
await gz.FlushAsync();
|
||||
}
|
||||
|
||||
var req = new HttpRequestMessage(HttpMethod.Post, "http://localhost:30888/upload") {
|
||||
Content = new ByteArrayContent(mem.ToArray()) {
|
||||
|
@ -95,14 +95,19 @@ public class Plugin : IDalamudPlugin {
|
|||
ContentEncoding = { "gzip" },
|
||||
},
|
||||
},
|
||||
// Content = new StringContent(json) {
|
||||
// Headers = { ContentType = new MediaTypeHeaderValue("application/json") },
|
||||
// },
|
||||
};
|
||||
|
||||
var resp = await this.Http.SendAsync(req);
|
||||
var output = await resp.Content.ReadAsStringAsync();
|
||||
Log.Info(output);
|
||||
try {
|
||||
var resp = await this.Http.SendAsync(req);
|
||||
if (resp.IsSuccessStatusCode) {
|
||||
Log.Verbose("uploaded successfully");
|
||||
} else {
|
||||
var output = await resp.Content.ReadAsStringAsync();
|
||||
Log.Warning($"could not upload data ({resp.StatusCode}): {output}");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Log.Warning(ex, "could not upload data");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue