redux-crud-store icon indicating copy to clipboard operation
redux-crud-store copied to clipboard

204 should be considered as a success

Open dzwiedziu-nkg opened this issue 7 years ago • 7 comments

When REST server response HTTP 204 No Content, you throw error "Unexpected end of JSON input". But, it is not error, it is success.

dzwiedziu-nkg avatar Apr 19 '17 06:04 dzwiedziu-nkg

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!

devvmh avatar Apr 19 '17 06:04 devvmh

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

devvmh avatar Apr 19 '17 06:04 devvmh

Ugh too hard to type this on my phone I'll edit the above comment on a laptop

devvmh avatar Apr 19 '17 06:04 devvmh

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.

devvmh avatar Apr 19 '17 06:04 devvmh

I prepared pull request with fix of this bug: #47

dzwiedziu-nkg avatar Apr 20 '17 21:04 dzwiedziu-nkg

Django REST Framework is a good platform to build sample CRUD backend app. https://tests4geeks.com/django-rest-framework-tutorial/

dzwiedziu-nkg avatar Jul 29 '17 02:07 dzwiedziu-nkg

You can see my progress at https://github.com/devvmh/demo-redux-crud-store

devvmh avatar Aug 07 '17 15:08 devvmh