-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Allow xhr errors to parse json responses. #3669
Conversation
@@ -157,7 +157,7 @@ export class Xhr { | |||
setupJson_(init); | |||
|
|||
return this.fetchAmpCors_(input, init).then(response => { | |||
return assertSuccess(response).json(); | |||
return assertSuccess(response).then(response => response.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.
Please un-nest.
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.
err.retriable = true; | ||
} | ||
if (response.headers.get('Content-Type') == 'application/json') { | ||
return response.json().then(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.
You can't return a new promise here - you are still in the constructor of the top-level promise. This is most likely not what you want. You probably just need to run promise w/o return values.
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.
Good catch. Done!
mockXhr.getResponseHeader = () => 'application/json'; | ||
const promise = assertSuccess( | ||
createResponseInstance('{"a": 2}', mockXhr)); | ||
promise.should.be.rejected; |
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.
@dvoytenko this catches the problem with returning the resolved promise. I don't understand it well tbh, but my guess is that the promise is resolving and the .should.be.rejected
won't catch this if we returned the resolved promise.
PTAL |
LGTM |
A split PR from #3583
ITI: #3343