-
-
Notifications
You must be signed in to change notification settings - Fork 158
Breaking change: null data returned when resource not found #631
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
Comments
the current response body is conform spec (except for the self link). Relevant passage:
It is the result of the rework of the serialization layer: it serializes Nevertheless the 404 was that was thrown previously was also conform spec. We could add a switch for that in |
I will make a separate issue for the bad self link |
Perhaps I am missing something, but the spec reads:
Both are not happening. The spec refers to a 200 with null data -or- a 404. This issue is about 404 comined with null data, which is not what the spec describes. A bit below:
What is currently implemented is not error details, but a success response body, combined with a http status code that represents an error. |
Ah -- my bad. I misread and thought it was returning a 200 with that error body. I will investigate and fix this next week. |
working on this. To the following, after discussion with @maurei :
|
Yep, that's correct. Elaborating on your last point
Would be good if an error object was returned. Pointers: |
I think this is not compliant with the spec:
|
The same line in the spec states an exception to that rule:
Where I believe the as described above refers to the following passage:
I.e. my reading of the specs is that when a route (i.e. relationship) exists ( But IMO all of this is pretty ambiguous :/ This rule + exception is explicitly formulated for fetching single resources. Nothing is stated about the analogous scenario of a has-many route (route |
I believe this applies solely to related data, as stated in the Note block below it and illustrated by the example. In short: Then, the spec resumes:
The "except when... described above" refers to the author example. In all other cases, 404 must be used. So I believe it is wrong to return 200 for |
This is in-line with what @maurei have discussed. However, we also discussed that the 200 should apply for when user id =1, exists and a GET request is sent to:
Books being a to-many resource, but this is not described in the spec, but we made a judgement call. We are in agreement, but the spec is ambiguous on the multiple resources front. |
Thanks for the clarification. |
#640 breaks our code. It throws at:
This is because we encode our IDs, to prevent callers guessing IDs. And in some cases, they contain additional information needed to fetch the right data. So our requests look like:
For this to work, we have a custom base class that derives from |
Looking at the changes, the trim/split/findindex url parsing feels a bit brittle to me. Wouldn't it be an option to use the route values, like it is done at:
For example, the debugger shows me for the request path:
these route values:
Hope this helps. |
Thank you, apparently the test cases were not comprehensive, the I did think that somebody would say that they have super-custom ids, but I didn't test it enough apparently ;) |
Having obfuscated ID's is a good use-case. A way forward could be to not throw in the current request middleware but just store the route data as is. This way the door is left open for extensibility as @bart-degreed describes, while still being able to generate a useful error response based on the obfuscated id |
Description
Earlier, when a resource does not exist, a 404 with an empty response body was returned. After fetch of latest master (with v4 merged in), I am now getting 404 with the next body:
Request URL: https://localhost/api/users/123
Response body:
Note the
self
link is wrong too: it misses the identity.Traced this down to
JsonApiDotNetCore/src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs
Line 108 in a801d95
The text was updated successfully, but these errors were encountered: