-
Notifications
You must be signed in to change notification settings - Fork 25
pretty print json on clicking fetch data button #137
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
Conversation
app/store/aliases.ts
Outdated
| }) | ||
| .then((data: axios.AxiosResponse) => { | ||
| const stringifiedData = JSON.stringify(data.data); | ||
| const stringifiedData = data.headers["content-type"].includes("json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need this condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dont need the pretty printing if the content-type is anything other than application/json. I had earlier added a strict equals condition for checking, but turns out that some websites sent out content-type headers as application/json; charset=utf-8. So this condition is needed to filter out types like text/html/text/plain or application/x-www-form-urlencoded for instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okey. but in the false part of this condition we are doing JSON.stringify doesn't that break for text/html?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite strange. I logged out the following
and intercepted a svg file, for which the output is:
running the following on chrome console or node repl gives me the following error
but we are getting the proper output for stringified data as you can see in first screenshot instead of it throwing an error. Not sure what is happening here.
Edit: Also note that the actions are getting dispatched with the proper payload and in proper order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean without JSON.stringify does the correct data coming to textbox?
like without escape?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, for non-json types, correct data is coming through. for json type, i am getting [object Object]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then why can't we remove the JSON.stringify for non JSON-types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Please check
app/store/aliases.ts
Outdated
| const stringifiedData = JSON.stringify(data.data); | ||
| const stringifiedData = data.headers["content-type"].includes("json") | ||
| ? JSON.stringify(data.data, null, 2) | ||
| : JSON.stringify(data.data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this will create issue when the response is html/xml?





No description provided.