-
Notifications
You must be signed in to change notification settings - Fork 46
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
Add support for parsing json response #32
base: master
Are you sure you want to change the base?
Conversation
I just rebased on top of master. Any chance I could get someone to look at this? |
Bump. Having same issue here, would love to see this PR merged 👍 |
fake_xml_http_request.js
Outdated
try { | ||
this.response = JSON.parse(this.responseText); | ||
} catch (e) { | ||
// Unable to parse JSON - no biggie |
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.
lets only catch errors related to parse failure. That we we don't swallow unexpected errors
src/fake-xml-http-request.js
Outdated
try { | ||
this.response = JSON.parse(this.responseText); | ||
} catch (e) { | ||
// Unable to parse JSON - no biggie |
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.
^
fake_xml_http_request.js
Outdated
@@ -447,6 +447,12 @@ | |||
} catch (e) { | |||
// Unable to parse XML - no biggie | |||
} | |||
} else if(this.responseText && /(application\/json)|(application\/vnd\.api\+json)/.test(type)) { |
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.
space between if
and (
src/fake-xml-http-request.js
Outdated
@@ -441,6 +441,12 @@ var FakeXMLHttpRequestProto = { | |||
} catch (e) { | |||
// Unable to parse XML - no biggie | |||
} | |||
} else if(this.responseText && /(application\/json)|(application\/vnd\.api\+json)/.test(type)) { |
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.
space between if
and (
left some things that need to be addressed. I believe this is a good change, and correct me if I'm wrong it will require a major version bump, right? |
I made the requested changes. I don't think it will require a major version bump. It only adds the I also added another commit updating the README to have the extra key in the documentation. |
I think this is related to my issue over at miragejs/ember-cli-mirage#1320. Any chance this can be merged? What else is left to do? |
@stefanpenner I believe this is good – ok to merge? |
@@ -447,6 +447,12 @@ | |||
} catch (e) { | |||
// Unable to parse XML - no biggie | |||
} | |||
} else if (this.responseText && /(application\/json)|(application\/vnd\.api\+json)/.test(type)) { | |||
try { | |||
this.response = JSON.parse(this.responseText); |
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 isn't correct in terms of the spec. There is always a response
no matter the responseType
, but there is only a responseText
when response type is text
. response
should be whatever the response type called for: string for text
, xml for xml
, object for json
, etc.
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.
@nlfurniss thanks, yes we should be careful to not deviate from the spec.
Could you briefly describe the implications of this violation? I suspect you have a use-case in-mind, and rather then guessing what the use-case is, knowing it will help the rest of us think about this correctly.
I likely have some follow up questions.
Also, do you see a path forward for the PR, or does your concern invalidate it entirely?
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.
My use-case is JSON, but it seemed like this semi-completeness might confuse people.
After looking at it again, I don't think it's a blocker but I'll create an issue after it lands setting out that response
is not 100% supported
@stefanpenner what do you think of the proposed changes? |
See #32 (comment). These changes don’t follow the XHR spec |
@samselikoff I think @nlfurniss's concerns likely need to be addressed. Spec violations can lead to some serious compat issues... |
Fixes #31