Skip to content

Commit

Permalink
feat: introduce NoContentException (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRouyer authored Oct 11, 2022
1 parent 14961f7 commit 82a5169
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/Pipedrive.net/Exceptions/NoContentException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Diagnostics;
using System.Net;

namespace Pipedrive
{
/// <summary>
/// Represents a HTTP 204 - No content response returned from the API.
/// </summary>
public class NoContentException : ApiException
{
/// <summary>
/// Constructs an instance of NoContentException
/// </summary>
/// <param name="response">The HTTP payload from the server</param>
public NoContentException(IResponse response) : this(response, null)
{
}

/// <summary>
/// Constructs an instance of NoContentException
/// </summary>
/// <param name="response">The HTTP payload from the server</param>
/// <param name="innerException">The inner exception</param>
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"; }
}
}
}
3 changes: 2 additions & 1 deletion src/Pipedrive.net/Http/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ async Task<IResponse> 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)
Expand Down

0 comments on commit 82a5169

Please sign in to comment.