Add default messages for custom exceptions

Right now, our exception messages come from the API response in most
cases. But if for any reason there isn't one, we supply a default. I
realized these messages might make it to people's logs so it might be
nice to spend time later making them even more useful.
This commit is contained in:
Haacked
2013-10-18 11:08:56 -07:00
parent a1887837be
commit c87944c884
15 changed files with 137 additions and 1 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ namespace Octokit
public override string Message
{
get { return ApiErrorMessageSafe; }
get { return ApiErrorMessageSafe ?? "Request Forbidden"; }
}
public HttpStatusCode StatusCode { get; private set; }
@@ -33,6 +33,11 @@ namespace Octokit
"ApiValidationException created with wrong status code");
}
public override string Message
{
get { return ApiErrorMessageSafe ?? "Validation Failed"; }
}
#if !NETFX_CORE
protected ApiValidationException(SerializationInfo info, StreamingContext context)
: base(info, context)
@@ -20,6 +20,11 @@ namespace Octokit
{
}
public override string Message
{
get { return ApiErrorMessageSafe ?? "Maximum number of login attempts exceeded"; }
}
#if !NETFX_CORE
protected LoginAttemptsExceededException(SerializationInfo info, StreamingContext context)
: base(info, context)
@@ -52,6 +52,13 @@ namespace Octokit
/// </summary>
public DateTimeOffset Reset { get; private set; }
// TODO: Might be nice to have this provide a more detailed message such as what the limit is,
// how many are remaining, and when it will reset. I'm too lazy to do it now.
public override string Message
{
get { return ApiErrorMessageSafe ?? "API Rate Limit exceeded"; }
}
#if !NETFX_CORE
protected RateLimitExceededException(SerializationInfo info, StreamingContext context)
: base(info, context)
@@ -23,6 +23,11 @@ namespace Octokit
{
}
public override string Message
{
get { return "The two-factor authentication code supplied is not correct"; }
}
#if !NETFX_CORE
protected TwoFactorChallengeFailedException(SerializationInfo info, StreamingContext context)
: base(info, context)
@@ -31,6 +31,11 @@ namespace Octokit
TwoFactorType = twoFactorType;
}
public override string Message
{
get { return ApiErrorMessageSafe ?? "Two-factor authentication code is required"; }
}
#if !NETFX_CORE
protected TwoFactorRequiredException(SerializationInfo info, StreamingContext context)
: base(info, context)