Closed nishant-shah-social closed 3 hours ago
Hi @nishant-shah-social, can you provide a bit more information here please? Where are you seeing this error please?
If you can provide information about your setup, that would be very helpful.
For example, the following details will be necessary for us to investigate this:
Any other information you can provide that might help us will be very helpful as well. Thanks!
Hi @nishant-shah-social, can you provide a bit more information here please? Where are you seeing this error please?
If you can provide information about your setup, that would be very helpful.
For example, the following details will be necessary for us to investigate this:
- How are you running Flagsmith? SaaS or self-hosted?
- How are you initialising your SDK? Please provide code examples where possible.
Any other information you can provide that might help us will be very helpful as well. Thanks!
Sure @matthewelwell ! We are using flagsmith self-hosted. The server is at version 2.129.0 We are using local evaluation mode
the code snippet
flagsmithConf := flagsmith.Configuration{
Environment: cfg.FlagsmithClient.Environment,
ApplicationName: cfg.FlagsmithClient.ApplicationName,
ServerSideAPIKey: cfg.FlagsmithClient.ServerSideApiKey,
ClientSideAPIKey: cfg.FlagsmithClient.ClientSideApikey,
BaseURL: cfg.FlagsmithClient.BaseURL,
RequestTimeout: cfg.FlagsmithClient.RequestTimeout,
Retries: cfg.FlagsmithClient.Retries,
RetryDelayInterval: cfg.FlagsmithClient.RetryDelayInterval,
EnvironmentRefreshInterval: cfg.FlagsmithClient.EnvironmentRefreshInterval,
EvaluationMode: flagsmith.EvaluationMode(cfg.FlagsmithClient.EvaluationMode),
FlagsmithCtx: flagsmithCtx,
PrometheusRegisterer: reg,
Logger: l,
UserAgent: fmt.Sprintf("%s,%s", cfg.FlagsmithClient.ApplicationName, cfg.FlagsmithClient.Environment),
}
flagClient, err := flagsmith.NewFlagsmithClient(flagsmithConf)
where NewflagsmithClient() has the logic to set all the options and then initialize flagsmith with something like:-
client := flagsmith.NewClient(apiKey, flagsmithOpts...)
While evaluation, we use following call:-
identityFlags, err := fg.Client.GetIdentityFlags(fg.ctx, idStr, fgTraits)
Hope this helps! Let me know if any further info is required
Thanks, Nishant Shah
Thanks for the details @nishant-shah-social, we'll take a look into this and update here with any findings.
@gagantrivedi incase you got time to look into it?
@nishant-shah-social The error sounds like your self-hosted Flagsmith is returning HTML instead of JSON. Could you double check that your API URL is something like https://flagsmith.example.com/api/v1/
? The trailing slash is needed.
@nishant-shah-social did you have a chance to confirm regarding the outstanding question here?
@rolodato @matthewelwell Sorry for the delayed response. Our API URL does have this trailing slash. I see this error happening intermittently and not always. Further investigations revealed that his error occurs when due to some reason SDK is unable to connect to flagsmith when trying to call update environment. Still I would expect some logical error instead of this
I believe we're not handling this case correctly, where the API responds with a non-JSON 4xx-5xx response: https://github.com/Flagsmith/flagsmith-go-client/blob/ad6f7fe973687722680141f14b7e8dc7b9ebe260/internal/flaghttp/request.go#L150-L152.
There's probably no need to unmarshal JSON at all here and we can just return the status code as an error, which is what we're trying to do here anyway: https://github.com/Flagsmith/flagsmith-go-client/blob/ad6f7fe973687722680141f14b7e8dc7b9ebe260/internal/flaghttp/request.go#L161-L165. We'd appreciate a PR for this if you have the time :)
Intermittently getting following errors after upgrading to the golang client sdk version 3.5.0:-
Failed to update environment: invalid character '<' looking for beginning of value
"Failed to update environment: invalid character 'E' looking for beginning of value"
Any help will be highly appreciatedThanks!