Skip to content
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

204 should be considered as a success #46

Open
dzwiedziu-nkg opened this issue Apr 19, 2017 · 7 comments
Open

204 should be considered as a success #46

dzwiedziu-nkg opened this issue Apr 19, 2017 · 7 comments

Comments

@dzwiedziu-nkg
Copy link

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

@devvmh
Copy link
Owner

devvmh commented Apr 19, 2017

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
Copy link
Owner

devvmh commented Apr 19, 2017

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 devvmh closed this as completed Apr 19, 2017
@devvmh devvmh reopened this Apr 19, 2017
@devvmh
Copy link
Owner

devvmh commented Apr 19, 2017

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

@devvmh
Copy link
Owner

devvmh commented Apr 19, 2017

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.

@dzwiedziu-nkg
Copy link
Author

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

dzwiedziu-nkg added a commit to dzwiedziu-nkg/books-collection-frontend that referenced this issue Apr 22, 2017
@dzwiedziu-nkg
Copy link
Author

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

@devvmh
Copy link
Owner

devvmh commented Aug 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants