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
Sometime response.data is string instead of object #1723
Comments
Is the |
@robmcguinness Yes, it's application/json |
I see the same behaviour. I found that in my case the API response would sometimes contain invalid JSON data, i.e. |
I got this problem, too. When i check |
I've checked with Axios, XMLHttpRequest, fetch |
I know there are some chars can lead to that problem, just need to be sure. |
@OpenGG sorry for late response, what you need here :D |
@huy-lv Not what I'm expecting. Please save the response with curl, then attach the saved file by dropping it to this issue's reply area. |
Never mind, found it. file: https://gist.github.com/OpenGG/ac72e79f9ef088e993213473116c0cd0 |
i know, this problem does not happen all the time, it's about 1-2 times each 10 requests (the same API, same response) |
@OpenGG it happen on React-Native. Web App work perfectly. |
Could you make an online demo on expo, and share it? This demo should make the same request with both Axios and XMLHttpRequest, to determine whether Axios or RN cause this issue. |
@OpenGG can you give me your mail i'll send you api, i can't public that |
Any luck with this issue? I'm facing it too |
@Druthi now im using 'fetch' instead of 'axios' |
any update? |
This might not your case but in my case: |
I have migrated my app (redux-saga,axios) to webpack4 and now response.data is a string instead of object. The migration changes I made are minimal to compile successfully webpack-config.js |
I ran JSON.parse(response.data) and the JSON is corrupt. (Unexpected token : in JSON at position 8181)
I compared with my pre migration webpack3 code where the JSON in response.data is OK (object). So the migrated code is managing to corrupt the JSON in response.data and that is why it is appearing as a string. So now the question is why is the JSON corrupt |
I solved the problem by downgrading to "webpack-dev-server": "3.1.10" I have a devServer proxy which I guess is the cause of the response corruption for versions greater then 3.1.10 |
@petercutting it is also a problem in production environment, haven't you observed? |
@nyilmaz my problem turned out to be caused by webpack-dev-server. webpack-dev-server would not be used in a production environment |
@petercutting did you open an issue against webpack-dev-server? I couldn't find on. |
@goodmorninggoaway I dont remember. probably not |
Irrespective of the webpack-dev-server issues, Axios shouldn't silently swallow I was just testing the robustness of an app by sending malformed JSON from the backend. The Axios request silently fails to decode the JSON. The header It's quite crazy that a library with 60k stars has such a basic bug for half a year 😕 |
Parfectly valid |
Any update on this bug for react native!? |
I found that this happens when the json response from the server is invalid, use a json validator like https://jsonlint.com/ to make sure that your json is correctly formatted |
The error swallowing issue is being tracked, I will be closing this issue as it's essentially a duplicate of it. Please reach out if you have any questions. |
@fed135 please link the relevant issue if any, thanks. |
Anyone solved this yet?, I'm using laravel as my API, so i logged my response before sending it to my app. The logged response is a valid JSON but the received response has the last "}" brace missing at the end, making it an invalid response. I don't know why this is behaving like this on my mobile app, cause for the frontend app it which uses axios too it works fine, tried on postman too, it works fine. any ideas or solutions pls?? |
It happens when data gets too large :( I didnt have any problems since the data array was small! |
@matinzd I paginate my data, and only return 20 |
@matinzd and also, my fronend app uses the same endpoint, and it doesn't experience that, only the mobile app with react native does sometimes |
please my laravel api is coming out as a string alongside <!--, and looping through is like looking through a string |
I have finally found a solution to mine. And I solved it by: Axios.get(uri) |
I have the same error |
Got the same issue, after check in jsonlint.com I have the data with Error: Parse error on line 186:
..., "position_name": NaN, "group_name":
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined' |
Same error, who can fixed it :| |
☝️ I made a quick PR to address this issue. Hopefully it helps |
Getting this issue in react-native with axios 0.19.2 |
I got this same issue, I solved this problem make change in method of axios, if you had 'GET' method you can t send body because you can get this issue, to solve this you need to change to 'POST' and it will be working |
I don't know why but with the same api, sometime axios's response.data is string instead of object. See the below figure.
Context
The text was updated successfully, but these errors were encountered: