mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 19:26:51 +00:00
Merge pull request #87 from octokit/haacked/more-exception-defaults
Fixing up the defaults a bit
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user