Skip to content

Commit

Permalink
RequestCore > fix 'Unable to cast object of type 'System.Int64' to ty…
Browse files Browse the repository at this point in the history
…pe 'Newtonsoft.Json.Linq.JArray' error (#236)

Github issue: #235
  • Loading branch information
dhabierre authored Jan 21, 2024
1 parent eae8d82 commit f46be2b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion MegaApiClient/MegaApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ private TResponse RequestCore<TResponse>(RequestBase request, byte[] key)
var uri = GenerateUrl(request.QueryArguments);
object jsonData = null;
var attempt = 0;
var apiCode = ApiResultCode.Ok;
while (_options.ComputeApiRequestRetryWaitDelay(++attempt, out var retryDelay))
{
var dataResult = _webClient.PostRequestJson(uri, dataRequest);
Expand All @@ -1124,7 +1125,7 @@ private TResponse RequestCore<TResponse>(RequestBase request, byte[] key)
|| jsonData is long
|| jsonData is JArray array && array[0].Type == JTokenType.Integer)
{
var apiCode = jsonData == null
apiCode = jsonData == null
? ApiResultCode.RequestFailedRetry
: jsonData is long
? (ApiResultCode)Enum.ToObject(typeof(ApiResultCode), jsonData)
Expand All @@ -1150,6 +1151,11 @@ private TResponse RequestCore<TResponse>(RequestBase request, byte[] key)
break;
}

if (apiCode != ApiResultCode.Ok)
{
throw new ApiException(apiCode);
}

var data = ((JArray)jsonData)[0].ToString();
return (typeof(TResponse) == typeof(string)) ? data as TResponse : JsonConvert.DeserializeObject<TResponse>(data, new GetNodesResponseConverter(key));
}
Expand Down

0 comments on commit f46be2b

Please sign in to comment.