Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom exception for the HTTP 451 response #1239

Merged
merged 5 commits into from
Apr 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Octokit.Tests/Exceptions/LegalRestrictionExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Net;
using Octokit.Internal;
using Xunit;

namespace Octokit.Tests.Exceptions
{
public class LegalRestrictionExceptionTests
{
[Fact]
public void HasDefaultMessage()
{
var response = new Response(HttpStatusCode.Forbidden, null, new Dictionary<string, string>(), "application/json");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldnt the status code here be the HTTP 451 (not Forbidden?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really sorry for this, I'll fix this. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to apologosie! Everyone's contributions are much appreciated 😀

var legalRestrictionException = new LegalRestrictionException(response);

Assert.Equal("Resource taken down due to a DMCA notice.", legalRestrictionException.Message);
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<Compile Include="Exceptions\ApiErrorTests.cs" />
<Compile Include="Exceptions\ApiExceptionTests.cs" />
<Compile Include="Exceptions\ApiValidationExceptionTests.cs" />
<Compile Include="Exceptions\LegalRestrictionExceptionTests.cs" />
<Compile Include="Exceptions\RepositoryExistsExceptionTests.cs" />
<Compile Include="Exceptions\TwoFactorChallengeFailedException.cs" />
<Compile Include="Exceptions\ForbiddenExceptionTests.cs" />
Expand Down
5 changes: 5 additions & 0 deletions Octokit/Exceptions/LegalRestrictionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ namespace Octokit
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class LegalRestrictionException : ApiException
{
public override string Message
{
get { return ApiErrorMessageSafe ?? "Resource taken down due to a DMCA notice."; }
}

/// <summary>
/// Constructs an instance of LegalRestrictionException
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@
<Compile Include="Models\Request\UserRename.cs" />
<Compile Include="Models\Response\UserRenameResponse.cs" />
<Compile Include="Models\Request\NewPublicKey.cs" />
<Compile Include="Exceptions\LegalRestrictionException.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
3 changes: 2 additions & 1 deletion Octokit/Octokit-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@
<Compile Include="Models\Request\UserRename.cs" />
<Compile Include="Models\Response\UserRenameResponse.cs" />
<Compile Include="Models\Request\NewPublicKey.cs" />
<Compile Include="Exceptions\LegalRestrictionException.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
</Project>
3 changes: 2 additions & 1 deletion Octokit/Octokit-Monotouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@
<Compile Include="Models\Request\UserRename.cs" />
<Compile Include="Models\Response\UserRenameResponse.cs" />
<Compile Include="Models\Request\NewPublicKey.cs" />
<Compile Include="Exceptions\LegalRestrictionException.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
1 change: 1 addition & 0 deletions Octokit/Octokit-Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@
<Compile Include="Models\Request\UserRename.cs" />
<Compile Include="Models\Response\UserRenameResponse.cs" />
<Compile Include="Models\Request\NewPublicKey.cs" />
<Compile Include="Exceptions\LegalRestrictionException.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit-netcore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
<Compile Include="Models\Request\UserRename.cs" />
<Compile Include="Models\Response\UserRenameResponse.cs" />
<Compile Include="Models\Request\NewPublicKey.cs" />
<Compile Include="Exceptions\LegalRestrictionException.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
Expand Down