crowdin / crowdin-api-client-dotnet

.NET client library for Crowdin API
https://www.nuget.org/packages/Crowdin.Api/
MIT License
53 stars 26 forks source link

C# API Client: StringBatchOperations doesn't work #150

Closed seif-aljane closed 1 year ago

seif-aljane commented 1 year ago

Is this a regression? No. StringBatchOperations wasn't available in 2.12

In which version? 2.14

Description We're currently working on the C# Crowdin API’s StringBatchOperations and we faced the following issue:

{ "ClassName": "System.NullReferenceException", "Message": "Object reference not set to an instance of an object.", "StackTraceString": " at Crowdin.Api.Core.JsonParser.ParseResponseObject[TData](JToken token)\r\n at Crowdin.Api.Core.JsonParser.ParseResponseList[TData](JObject rootElement)\r\n at Crowdin.Api.SourceStrings.SourceStringsApiExecutor.StringBatchOperations(Int32 projectId, IEnumerable1 patches)\r\n", }

When debugging in the SourceStringsApiExecutor.cs, we found that the http response from CrowdinAPI has the status 200 OK and is returning the following jsonObject:

{ "data": [ { ""data"": { ""id"": 468549, ""projectId"": 11, ""fileId"": 1533, ""branchId"": null, ""directoryId"": 1535, ""identifier"": ""bulk_edit_6"", ""text"": ""Batch operations with send patch request"", ""type"": ""text"", ""context"": ""edited context using patch request"", ""maxLength"": 0, ""isHidden"": false, ""isDuplicate"": false, ""masterStringId"": null, ""revision"": 58, ""hasPlurals"": false, ""isIcu"": false, ""labelIds"": [], ""createdAt"": ""2023-06-05T12:00:32+02:00"", ""updatedAt"": ""2023-06-05T18:38:26+02:00"" } } ] }

As you can see, the response is missing the pagination object (like mentioned in CrowdinAPI) which is probably why the line return _jsonParser.ParseResponseList<SourceString>(crowdinApiResult.JsonObject); in SourceStringsApiExecutor.cs fails to parse it and triggers the NullReferenceException.

Please provide a link to a minimal reproduction of the bug

A simple call of StringBatchOperations.

Please provide the exception or error you saw

{ "ClassName": "System.NullReferenceException", "Message": "Object reference not set to an instance of an object.", "Data": null, "InnerException": null, "HelpURL": null, "StackTraceString": " at Crowdin.Api.Core.JsonParser.ParseResponseObject[TData](JToken token)\r\n at Crowdin.Api.Core.JsonParser.ParseResponseList[TData](JObject rootElement)\r\n at Crowdin.Api.SourceStrings.SourceStringsApiExecutor.StringBatchOperations(Int32 projectId, IEnumerable1 patches)\r\n", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": null, "HResult": -2147467261, "Source": "Crowdin.Api", "WatsonBuckets": null }

innomaxx commented 1 year ago

Hello @seialj. Thanks for this issue, we're currently working on it. Stay tuned!

innomaxx commented 1 year ago

@andrii-bodnar is it ok that the remote side returned ResponseList object without Pagination properties? If yes - we can make them optional

andrii-bodnar commented 1 year ago

@innomaxx yes, it can be optional