Skip to content

Commit

Permalink
Fixed missing resource in JSON overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Jan 17, 2022
1 parent b7a17e0 commit 10dc0e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/RestSharp/RestClient.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public partial class RestClient {
// to a transport or framework exception. HTTP errors should attempt to
// be deserialized
if (response.Content != null) {
var handler = GetContentDeserializer(raw, request.RequestFormat);

// Only continue if there is a handler defined else there is no way to deserialize the data.
// This can happen when a request returns for example a 404 page instead of the requested JSON/XML resource
var handler = GetContentDeserializer(raw, request.RequestFormat);

if (handler is IXmlDeserializer xml && request is RestXmlRequest xmlRequest) {
if (xmlRequest.XmlNamespace.IsNotEmpty()) xml.Namespace = xmlRequest.XmlNamespace!;

Expand Down
6 changes: 3 additions & 3 deletions src/RestSharp/RestClientExtensions.Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static partial class RestClientExtensions {
TRequest request,
CancellationToken cancellationToken = default
) where TRequest : class {
var restRequest = new RestRequest().AddJsonBody(request);
var restRequest = new RestRequest(resource).AddJsonBody(request);
return client.PostAsync<TResponse>(restRequest, cancellationToken);
}

Expand All @@ -86,7 +86,7 @@ public static partial class RestClientExtensions {
TRequest request,
CancellationToken cancellationToken = default
) where TRequest : class {
var restRequest = new RestRequest().AddJsonBody(request);
var restRequest = new RestRequest(resource).AddJsonBody(request);
var response = await client.PostAsync(restRequest, cancellationToken).ConfigureAwait(false);
return response.StatusCode;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public static partial class RestClientExtensions {
TRequest request,
CancellationToken cancellationToken = default
) where TRequest : class {
var restRequest = new RestRequest().AddJsonBody(request);
var restRequest = new RestRequest(resource).AddJsonBody(request);
var response = await client.PutAsync(restRequest, cancellationToken).ConfigureAwait(false);
return response.StatusCode;
}
Expand Down

0 comments on commit 10dc0e3

Please sign in to comment.