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

Commit 74ee170

Browse files
committed
Merge pull request #170 from github/fixes/detect-enterprise-host
Cleanup enterprise host detection code
2 parents 10ddb7d + 9186eb6 commit 74ee170

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-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 ApiExceptionExtensions
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/GitHub.Exports.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Link>Key.snk</Link>
9898
</None>
9999
<Compile Include="Collections\ICopyable.cs" />
100+
<Compile Include="ExceptionExtensions.cs" />
100101
<Compile Include="Helpers\INotifyPropertySource.cs" />
101102
<Compile Include="Extensions\PropertyNotifierExtensions.cs" />
102103
<Compile Include="Extensions\SimpleRepositoryModelExtensions.cs" />

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)