Merge pull request #87 from octokit/haacked/more-exception-defaults

Fixing up the defaults a bit
This commit is contained in:
Phil Haack
2013-10-18 11:33:54 -07:00
3 changed files with 44 additions and 2 deletions
+29 -1
View File
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization.Formatters.Binary;
@@ -13,6 +14,33 @@ namespace Octokit.Tests.Exceptions
{
public class TheConstructor
{
[Fact]
public void SetsDefaultExceptionMessage()
{
var exception = new ApiException();
Assert.Equal("An error occurred with this API request", exception.Message);
}
[Fact]
public void SetsSpecifiedExceptionMessageAndInnerException()
{
var inner = new InvalidOperationException();
var exception = new ApiException("Shit broke", inner);
Assert.Equal("Shit broke", exception.Message);
Assert.Same(inner, exception.InnerException);
}
[Fact]
public void SetsSpecifiedExceptionMessageAndStatusCode()
{
var exception = new ApiException("Shit still broke", HttpStatusCode.Gone);
Assert.Equal("Shit still broke", exception.Message);
Assert.Equal(HttpStatusCode.Gone, exception.StatusCode);
}
[Fact]
public void CreatesGitHubErrorFromJsonResponse()
{
+11 -1
View File
@@ -20,6 +20,16 @@ namespace Octokit
{
}
public ApiException(string message, HttpStatusCode httpStatusCode)
: this(new ApiResponse<object> {Body = message, StatusCode = httpStatusCode})
{
}
public ApiException(string message, Exception innerException)
: this(new ApiResponse<object> { Body = message }, innerException)
{
}
public ApiException(IResponse response)
: this(response, null)
{
@@ -36,7 +46,7 @@ namespace Octokit
public override string Message
{
get { return ApiErrorMessageSafe ?? "Request Forbidden"; }
get { return ApiErrorMessageSafe ?? "An error occurred with this API request"; }
}
public HttpStatusCode StatusCode { get; private set; }
+4
View File
@@ -24,6 +24,10 @@ namespace Octokit
"ForbiddenException created with wrong status code");
}
public override string Message
{
get { return ApiErrorMessageSafe ?? "Request Forbidden"; }
}
#if !NETFX_CORE
protected ForbiddenException(SerializationInfo info, StreamingContext context)