Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgos07 committed Nov 2, 2018
1 parent a8d3b66 commit 5ffc697
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/Incontrl.Sdk/Http/JsonResponse.cs
Expand Up @@ -17,36 +17,32 @@ internal class JsonResponse : JsonResponse<string>

internal class JsonResponse<T>
{
// Private variables.
private readonly T _data;
private bool _isHttpError;
private HttpStatusCode _httpErrorstatusCode;
private string _httpErrorReason;
private readonly string _httpErrorReason;
private JObject _errors;

// Class properties.
public bool IsHttpError => _isHttpError;
public HttpStatusCode HttpErrorStatusCode => _httpErrorstatusCode;
public T Data => _data;
public bool IsHttpError { get; private set; }
public HttpStatusCode HttpErrorStatusCode { get; private set; }
public T Data { get; private set; }

public JsonResponse(string raw) {
try {
if (null == raw) {
_data = default(T);
Data = default(T);
} else if (typeof(T).Equals(typeof(string))) {
_data = (T)(object)raw;
Data = (T)(object)raw;
} else {
var settings = new JsonSerializerSettings();
_data = JsonConvert.DeserializeObject<T>(raw, settings);
Data = JsonConvert.DeserializeObject<T>(raw, settings);
}
} catch (Exception exception) {
throw new InvalidOperationException($"Invalid JSON response: {exception}");
}
}

public JsonResponse(string raw, HttpStatusCode statusCode, string reason) {
_isHttpError = true;
_httpErrorstatusCode = statusCode;
IsHttpError = true;
HttpErrorStatusCode = statusCode;
_httpErrorReason = reason;

try {
Expand Down

0 comments on commit 5ffc697

Please sign in to comment.