redux-crud-store
redux-crud-store copied to clipboard
204 should be considered as a success
When REST server response HTTP 204 No Content, you throw error "Unexpected end of JSON input". But, it is not error, it is success.
Hi thanks for reporting this.
Could you provide a code sample or at least a sketch to help me reproduce the problem? If so, i can probably get a fix out this week. Otherwise it may be a while, since I'm not sure what the exact problem is based in your description.
Thanks! And thanks again for reporting the issue!
Ok so i took a quick look at what might cause this error. I may be confused about where this error is arising, so i eagerly await sample code.
If it's the error I'm guessing it is, the problem is that the app defaults to a json format in the api client. The default api client is configurable to allow changing that value.
The README suggests using this line to configure the api client when you kick off your saga
const client = new ApiClient({ basePath: 'https://example.com/api/v1' })
I suggest you try changing that to this
const client = new ApiClient({
basePath: 'https://example.com/api/v1',
format: 'text'
})
This will call response.text () instead of response.json () in ApiClient.js which may resolve the problem.
If not post more details here and i can help troubleshoot further
Ugh too hard to type this on my phone I'll edit the above comment on a laptop
Also note that you can use the fetchconfig param in your action creators to achieve the same thing on one endpoint instead of on all of them. You probably only want the text format for the endpoints returning 204.
The other alternative is copy pasting ApiClient.js into your codebase and customizing it. I'd hot go that route and create useful improvements, please make a pull request! Id love to see how your use case works.
I prepared pull request with fix of this bug: #47
Django REST Framework is a good platform to build sample CRUD backend app. https://tests4geeks.com/django-rest-framework-tutorial/
You can see my progress at https://github.com/devvmh/demo-redux-crud-store