Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

fix: public profile should be null when NO_CONTENT #1020

Closed
wants to merge 1 commit into from

Conversation

spaenleh
Copy link
Member

@spaenleh spaenleh commented Jan 24, 2025

In this PR I fix an issue related to the data that is returned by react-query when getting a public profile of a own profile that does not exist.

Currently, when we ask for the user's own profile or a member public profile and they do not exist yet, the backend return a 204 NO_CONTENT response. This results in a data property in axios that is actually an empty string ''.

Instead we expect to have a null value to be stored in the query cache.

The null value is necessary in order to discriminate between the query being fetched (undefined) and the data not being available on the server null.

How it was fixed

In order to fix this issue, I added a check for the statusCode of the response and if it is 204, I return null

This was done to the ownProfile as well as the memberProfile (any member).

Tests were added to ensure this behaviour is guaranteed.

Thoughts

Seeing as axios is handling missing responses with empty strings, I am not sure that our approach is right. Semantically I prefer the data to be null than empty string when the profile does not exist, however having to manually deal with it, is cumbersome and error-prone. On the other side, I am not sure that returning an error code would necessarily be better... To be discussed if we think this needs to be changed in the future, for now this fix should do.

@spaenleh spaenleh requested review from MatveyK and pyphilia January 24, 2025 08:36
@spaenleh spaenleh self-assigned this Jan 24, 2025
@spaenleh spaenleh added the bug 🪲 Something isn't working label Jan 24, 2025
@spaenleh
Copy link
Member Author

Closing as we discussed it would be better to handle this case in the backend.

The plan will be to revert to using a 200 OK with a response of null. This will allow us to use the generation from the API without having to manually change the data stored in the query-client for each response. We loose the semantic sens of the 204 NO_CONTENT but at the benefice of less manual work on each query.

@spaenleh spaenleh closed this Jan 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant