Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequestCore > fix 'Unable to cast object of type 'System.Int64' to type 'Newtonsoft.Json.Linq.JArray' error #236

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Changes from all 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
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
Loading