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

Receiving Json Parsing error when receiving 304 status when ETag in response header is null. #206

Closed
PeterDierckx78 opened this issue Feb 7, 2024 · 1 comment · Fixed by #208

Comments

@PeterDierckx78
Copy link

PeterDierckx78 commented Feb 7, 2024

Describe the bug
Each time FetchToggles is called when no feature flags have changed we see a logging that the Json serializer can not parse the empty response.

To Reproduce
Steps to reproduce the behavior:

  1. Configure unleash with appName, projectId, apiKey, url, we use the System.Text.Json.JsonSerializer
  2. Create an Unleashclient with FetchToggleInterval set to i.e. 20 seconds.
  3. Call the client.IsEnabled("any flag", context)
  4. Wait for next fetch interval
  5. See error

Expected behavior
We should see no errors.

Actual behavior
In the logs you see that the error appears:
The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.",

Desktop (please complete the following information):

  • OS: Windows
  • Browser chrome
  • Version 4.1.5 (latest at the moment of writing)

Additional context
After some debugging I see that when the status 304 is received (= NOTMODIFIED) we enter the HandleSuccessResponse() function in the UnleashApiClient.cs file.
There first a check is made if the eTag has changed. If not the response.Content is Deserialized but since it is empty an error is thrown.

This can easily be fixed by extending the condition "if(newEtag == etag)" to:

        if (newEtag == etag || response.StatusCode == HttpStatusCode.NotModified)
        {
            return new FetchTogglesResult
            {
                HasChanged = false,
                Etag = newEtag,
                ToggleCollection = null,
            };
        }

So in the case the status = NOTMODIFIED we directly return that there were no changes.

Can this bugfix taken up a.s.a.p.?

@PeterDierckx78
Copy link
Author

Thanks for applying this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant