mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 19:26:51 +00:00
Add NotFoundException for 404 status
This commit is contained in:
@@ -231,6 +231,28 @@ namespace Octokit.Tests.Http
|
||||
Assert.Equal("http://developer.github.com/v3", exception.ApiError.DocumentationUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ThrowsNotFoundExceptionForFileNotFoundResponse()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse<string> response = new ApiResponse<string>
|
||||
{
|
||||
StatusCode = HttpStatusCode.NotFound,
|
||||
Body = "GONE BYE BYE!"
|
||||
};
|
||||
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
|
||||
var connection = new Connection("Test Runner User Agent",
|
||||
ExampleUri,
|
||||
Substitute.For<ICredentialStore>(),
|
||||
httpClient,
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var exception = await AssertEx.Throws<NotFoundException>(
|
||||
async () => await connection.GetAsync<string>(new Uri("/endpoint", UriKind.Relative)));
|
||||
|
||||
Assert.Equal("GONE BYE BYE!", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ThrowsForbiddenExceptionForUnknownForbiddenResponse()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
#if !NETFX_CORE
|
||||
[Serializable]
|
||||
#endif
|
||||
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
|
||||
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
|
||||
public class NotFoundException : ApiException
|
||||
{
|
||||
public NotFoundException(IResponse response) : this(response, null)
|
||||
{
|
||||
}
|
||||
|
||||
public NotFoundException(IResponse response, Exception innerException) : base(response, innerException)
|
||||
{
|
||||
Debug.Assert(response != null && response.StatusCode == HttpStatusCode.NotFound,
|
||||
"NotFoundException created with wrong status code");
|
||||
}
|
||||
|
||||
#if !NETFX_CORE
|
||||
protected NotFoundException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -244,6 +244,11 @@ namespace Octokit
|
||||
throw exceptionFunc(response);
|
||||
}
|
||||
|
||||
if ((int)response.StatusCode == 404)
|
||||
{
|
||||
throw new NotFoundException(response);
|
||||
}
|
||||
|
||||
if ((int)response.StatusCode >= 400)
|
||||
{
|
||||
throw new ApiException(response);
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Clients\IssuesClient.cs" />
|
||||
<Compile Include="Exceptions\NotFoundException.cs" />
|
||||
<Compile Include="IIssuesClient.cs" />
|
||||
<Compile Include="Models\Issue.cs" />
|
||||
<Compile Include="Models\IssueRequest.cs" />
|
||||
|
||||
@@ -122,6 +122,7 @@
|
||||
<Compile Include="Exceptions\ApiException.cs" />
|
||||
<Compile Include="Exceptions\ApiValidationException.cs" />
|
||||
<Compile Include="Exceptions\AuthorizationException.cs" />
|
||||
<Compile Include="Exceptions\NotFoundException.cs" />
|
||||
<Compile Include="Exceptions\TwoFactorChallengeFailedException.cs" />
|
||||
<Compile Include="Exceptions\TwoFactorRequiredException.cs" />
|
||||
<Compile Include="Helpers\ApiUrls.cs" />
|
||||
|
||||
Reference in New Issue
Block a user