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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 servernull
.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 thememberProfile
(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 benull
thanempty 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.