diff --git a/src/Pipedrive.net/Exceptions/NoContentException.cs b/src/Pipedrive.net/Exceptions/NoContentException.cs new file mode 100644 index 00000000..03e6d474 --- /dev/null +++ b/src/Pipedrive.net/Exceptions/NoContentException.cs @@ -0,0 +1,37 @@ +using System; +using System.Diagnostics; +using System.Net; + +namespace Pipedrive +{ + /// + /// Represents a HTTP 204 - No content response returned from the API. + /// + public class NoContentException : ApiException + { + /// + /// Constructs an instance of NoContentException + /// + /// The HTTP payload from the server + public NoContentException(IResponse response) : this(response, null) + { + } + + /// + /// Constructs an instance of NoContentException + /// + /// The HTTP payload from the server + /// The inner exception + public NoContentException(IResponse response, Exception innerException) + : base(response, innerException) + { + Debug.Assert(response != null && response.StatusCode == HttpStatusCode.NoContent, + "NoContentException created with wrong status code"); + } + + public override string Message + { + get { return ApiErrorMessageSafe ?? "No content"; } + } + } +} diff --git a/src/Pipedrive.net/Http/Connection.cs b/src/Pipedrive.net/Http/Connection.cs index 4e9a69c2..700f8503 100644 --- a/src/Pipedrive.net/Http/Connection.cs +++ b/src/Pipedrive.net/Http/Connection.cs @@ -455,7 +455,8 @@ async Task RunRequest(IRequest request, CancellationToken cancellatio { (HttpStatusCode)422, response => new ApiValidationException(response) }, { (HttpStatusCode)429, response => new TooManyRequestsException(response) }, { HttpStatusCode.InternalServerError, response => new InternalServerErrorException(response) }, - { HttpStatusCode.NotImplemented, response => new NotImplementedException(response) } + { HttpStatusCode.NotImplemented, response => new NotImplementedException(response) }, + { HttpStatusCode.NoContent, response => new NoContentException(response) } }; static void HandleErrors(IResponse response)