Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Activout.RestClient.Test.Json/RestClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public async Task TestErrorAsync(JsonImplementation jsonImplementation)

Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode);
var error = exception.GetErrorResponse<ErrorResponse>();
Assert.NotNull(error);
Assert.Equal(34, error.Errors[0].Code);
Assert.Equal("Sorry, that page does not exist", error.Errors[0].Message);
}
Expand Down Expand Up @@ -165,6 +166,7 @@ public void TestErrorSync(JsonImplementation jsonImplementation)
Assert.Equal("Sorry, that page does not exist", message);

var error = exception.GetErrorResponse<ErrorResponse>();
Assert.NotNull(error);
Assert.Equal(34, error.Errors[0].Code);
Assert.Equal("Sorry, that page does not exist", error.Errors[0].Message);
}
Expand Down
1 change: 1 addition & 0 deletions Activout.RestClient.Xml.Test/ErrorResponseXmlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public async Task TestErrorResponse_Xml_BadRequest(string mediaType)
Assert.NotNull(exception.ErrorResponse);
Assert.IsType<XmlErrorResponse>(exception.ErrorResponse);
var errorResponse = exception.GetErrorResponse<XmlErrorResponse>();
Assert.NotNull(errorResponse);
Assert.Equal(400, errorResponse.Code);
Assert.Equal("Invalid request parameter", errorResponse.Message);
}
Expand Down
20 changes: 2 additions & 18 deletions Activout.RestClient/Part.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
#nullable disable
namespace Activout.RestClient
{
public class Part
{
internal object InternalContent { get; set; }
public string Name { get; set; }
public string FileName { get; set; }
}
namespace Activout.RestClient;

public class Part<T> : Part
{
public T Content
{
get => (T)InternalContent;
set => InternalContent = value;
}
}
}
public record Part(object Content, string? Name, string? FileName = null);
55 changes: 28 additions & 27 deletions Activout.RestClient/RestClientException.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
#nullable disable
using System;
using System.Net;

namespace Activout.RestClient
namespace Activout.RestClient;

public class RestClientException : Exception
{
public class RestClientException : Exception
public RestClientException(Uri? requestUri, HttpStatusCode statusCode, object? errorResponse)
: base(errorResponse?.ToString())
{
public RestClientException(Uri requestUri, HttpStatusCode statusCode, object errorResponse) : base(errorResponse?.ToString())
{
RequestUri = requestUri;
StatusCode = statusCode;
ErrorResponse = errorResponse;
}
RequestUri = requestUri;
StatusCode = statusCode;
ErrorResponse = errorResponse;
}

public RestClientException(Uri requestUri, HttpStatusCode statusCode, string errorResponse, Exception innerException) : base(
errorResponse, innerException)
{
RequestUri = requestUri;
StatusCode = statusCode;
ErrorResponse = errorResponse;
}
public RestClientException(Uri? requestUri, HttpStatusCode statusCode, string? errorResponse,
Exception? innerException)
: base(errorResponse, innerException)
{
RequestUri = requestUri;
StatusCode = statusCode;
ErrorResponse = errorResponse;
}

public Uri RequestUri { get; }
public HttpStatusCode StatusCode { get; }
public Uri? RequestUri { get; }
public HttpStatusCode StatusCode { get; }

public object ErrorResponse { get; }
public object? ErrorResponse { get; }

public T GetErrorResponse<T>()
{
return (T)ErrorResponse;
}
public T? GetErrorResponse<T>()
{
return (T?)ErrorResponse;
}

public override string ToString()
{
return $"{base.ToString()}, {nameof(RequestUri)}: {RequestUri}, {nameof(StatusCode)}: {StatusCode}, {nameof(ErrorResponse)}: {ErrorResponse}";
}
public override string ToString()
{
return
$"{base.ToString()}, {nameof(RequestUri)}: {RequestUri}, {nameof(StatusCode)}: {StatusCode}, {nameof(ErrorResponse)}: {ErrorResponse}";
}
}
Loading