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

fix(parsestatus): add response data to error #510

Merged
1 commit merged into from
Apr 22, 2020
Merged

Conversation

ghost
Copy link

@ghost ghost commented Apr 15, 2020

As discussed on app-platform. The body of the response that was attached to the error was already parsed, so once it reaches the app, it can't be parsed a second time and the data was lost.

This attaches the parsed data to the error under error.details (it if can be parsed). So error.details will now no longer be the response object.

p.s.: I used a try catch block as I found the synchronous notation easier to read in combination with async/await, but that's a bit subjective, so let me know if you'd like me to use the promise api.

@ghost ghost marked this pull request as ready for review April 15, 2020 14:43
@ghost ghost requested review from amcgee and varl April 15, 2020 14:43
Copy link
Member

@amcgee amcgee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to change the Typescript type of FetchError.details - it doesn't complain because the response.json() function returns an any type, but accessing it later and expecting arbitrary JSON should complain.

Other than that the change looks good to me! One minor optional comment (feel free to ignore).

I suppose we'll need to make sure this is flagged as a BREAKING CHANGE when merging too, though it's a silly one. Perhaps we could call this a "fix" since it was never specified in the docs and accessing the body of the response never worked?

I checked all the places I thought we might possibly be using this and only found one (unpublished) which shows we need to add an error type for Not Found (catching 404 errors)

@ghost
Copy link
Author

ghost commented Apr 20, 2020

I suppose we'll need to make sure this is flagged as a BREAKING CHANGE when merging too, though it's a silly one. Perhaps we could call this a "fix" since it was never specified in the docs and accessing the body of the response never worked?

Yeah a fix is fine with me. It all depends on what the intended api was I guess. So you'd prefer fix?

@ghost
Copy link
Author

ghost commented Apr 21, 2020

I think I've addressed all the comments with the above commits, and I've added tests where necessary. Let me know how you feel about the current state of the PR, whether you'd prefer a fix or a breaking change and then this should be good to go!

@ghost ghost force-pushed the change-parse-status branch 3 times, most recently from 1220f1c to 7b679d2 Compare April 21, 2020 09:43
@ghost ghost requested a review from amcgee April 21, 2020 11:52
@amcgee
Copy link
Member

amcgee commented Apr 21, 2020

Yeah a fix is fine with me. It all depends on what the intended api was I guess. So you'd prefer fix?

Yeah, it was basically broken before so let's say this is a fix.

Copy link
Member

@amcgee amcgee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ismay !! Sorry for the runaround on such a small change, added a couple more comments. I think we should leave the 404 addition for another change.

@ghost ghost force-pushed the change-parse-status branch from 16a8c53 to 574932b Compare April 22, 2020 08:03
@ghost
Copy link
Author

ghost commented Apr 22, 2020

Thanks @ismay !! Sorry for the runaround on such a small change, added a couple more comments. I think we should leave the 404 addition for another change.

No problem, I think it's good to think these kinds of changes over. I think I've addressed all the comments and I've removed the breaking change label. If you're ok with it let me know, I propose before merge we squash to the first commit message.

@ghost ghost requested a review from amcgee April 22, 2020 08:09
Copy link
Member

@amcgee amcgee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I made one request for stricter typings, but functionally it's identical. Thanks @ismay !

The error returned for failed fetches no longer contains the response under error.details. Instead error.details now contains the parsed response body, if it could be parsed.
@ghost ghost force-pushed the change-parse-status branch from 7d6d754 to 7dc6978 Compare April 22, 2020 10:07
@ghost ghost merged commit 5c124db into master Apr 22, 2020
@ghost ghost deleted the change-parse-status branch April 22, 2020 10:09
@ghost
Copy link
Author

ghost commented Apr 22, 2020

All right, done and done. Thanks for the help @amcgee 👍!

dhis2-bot added a commit that referenced this pull request Apr 22, 2020
## [2.1.2](v2.1.1...v2.1.2) (2020-04-22)

### Bug Fixes

* **parsestatus:** add response data to error ([#510](#510)) ([5c124db](5c124db))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 2.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants