Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 54f1424

Browse files
committed
Cleanup and consolidate check
1 parent 283bce3 commit 54f1424

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/GitHub.Api/SimpleApiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async Task<Repository> GetRepositoryInternal()
7474
catch (ApiException apiex)
7575
{
7676
if (!HostAddress.IsGitHubDotComUri(OriginalUrl.ToRepositoryUrl()))
77-
isEnterprise = apiex.HttpResponse?.Headers.ContainsKey("X-GitHub-Request-Id");
77+
isEnterprise = apiex.IsGitHubApiException();
7878
}
7979
catch {}
8080
finally
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using Octokit;
3+
4+
namespace GitHub.Extensions
5+
{
6+
public static class ExceptionExtensions
7+
{
8+
const string GithubHeader = "X-GitHub-Request-Id";
9+
public static bool IsGitHubApiException(this Exception ex)
10+
{
11+
var apiex = ex as ApiException;
12+
return apiex?.HttpResponse?.Headers.ContainsKey(GithubHeader) ?? false;
13+
}
14+
}
15+
}

src/GitHub.Exports/Services/EnterpriseProbeTask.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ public async Task<EnterpriseProbeResult> ProbeAsync(Uri enterpriseBaseUrl)
4141
var ret = await httpClient
4242
.Send(request, CancellationToken.None)
4343
.Catch(ex => {
44-
var apiex = ex as ApiException;
45-
if (apiex != null)
46-
success = apiex.HttpResponse?.Headers.ContainsKey("X-GitHub-Request-Id") ?? false;
44+
success = ex.IsGitHubApiException();
4745
return null;
4846
});
4947

0 commit comments

Comments
 (0)