-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw more appropriate exceptions based on HTTP response codes.
- Loading branch information
Tony Lechner
committed
May 24, 2016
1 parent
032acf7
commit b9f7ea9
Showing
4 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
Libraries/CloseIoDotNet/Rest/Exceptions/CloseIoRequestException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
namespace CloseIoDotNet.Rest.Exceptions | ||
{ | ||
using System; | ||
using System.Net; | ||
using RestSharp; | ||
|
||
public class CloseIoRequestException : Exception | ||
{ | ||
#region Constants | ||
private const string DefaultMessage = | ||
"Close.Io returned an unknown error to your request"; | ||
#endregion | ||
|
||
#region Instance Variables | ||
private HttpStatusCode? _statusCode; | ||
private string _body; | ||
#endregion | ||
|
||
#region Properties | ||
public IRestRequest RestRequest { get; set; } | ||
public IRestResponse RestResponse { get; set; } | ||
public HttpStatusCode ResponseStatusCode | ||
{ | ||
get | ||
{ | ||
if (_statusCode.HasValue == false) | ||
{ | ||
try | ||
{ | ||
_statusCode = RestResponse.StatusCode; | ||
} | ||
catch (Exception) | ||
{ | ||
_statusCode = new HttpStatusCode(); | ||
} | ||
} | ||
return _statusCode.Value; | ||
} | ||
set { _statusCode = value; } | ||
} | ||
public string ResponseBody | ||
{ | ||
get | ||
{ | ||
if (_body == null) | ||
{ | ||
try | ||
{ | ||
_body = RestResponse.Content; | ||
} | ||
catch (Exception) | ||
{ | ||
_body = string.Empty; | ||
} | ||
} | ||
return _body; | ||
} | ||
set { _body = value; } | ||
} | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
public CloseIoRequestException() : base(DefaultMessage) { } | ||
|
||
public CloseIoRequestException(string message) : base(message) { } | ||
|
||
public CloseIoRequestException(string message, Exception innerException) : base(message, innerException) { } | ||
#endregion | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Libraries/CloseIoDotNet/Rest/Exceptions/InternalServerErrorException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace CloseIoDotNet.Rest.Exceptions | ||
{ | ||
using System; | ||
public class InternalServerErrorException : Exception | ||
{ | ||
#region Constants | ||
public const string DefaultMessage = | ||
"Close.Io encountered an unexpected internal server error (HTTP 500) while processing your request."; | ||
#endregion | ||
|
||
#region Constructors | ||
public InternalServerErrorException() : base(DefaultMessage) { } | ||
|
||
public InternalServerErrorException(string message) : base(message) { } | ||
|
||
public InternalServerErrorException(string message, Exception innerException) : base(message, innerException) { } | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters