refactor: 重构 Gitee 健康检查

This commit is contained in:
Argo-Tianyi 2021-11-07 12:10:07 +08:00
parent edac104fbc
commit 03ceefcd11
1 changed files with 10 additions and 3 deletions

View File

@ -42,10 +42,17 @@ namespace Bootstrap.Admin.HealthChecks
{
var sw = Stopwatch.StartNew();
Exception? error = null;
var result = await _client.HttpClient.GetFromJsonAsync<object>($"/api/Gitee/{url}", cancellationToken);
object? result = null;
try
{
result = await _client.HttpClient.GetFromJsonAsync<object>($"/api/Gitee/{url}", cancellationToken);
}
catch (Exception ex) { error = ex; }
sw.Stop();
data.Add(url, error == null ? $"{result} Elapsed: {sw.Elapsed}" : $"{result} Elapsed: {sw.Elapsed} Exception: {error}");
})).ToArray());
data.Add(url, error == null
? $"{result} Elapsed: {sw.Elapsed}"
: $"Elapsed: {sw.Elapsed} Exception: {error}");
})).ToArray(), cancellationToken);
return Task.FromResult(HealthCheckResult.Healthy("Ok", data));
}
}