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

V1 - Updating the routing #394

Merged
merged 7 commits into from
Apr 4, 2022
Merged

Conversation

sakshibobade21
Copy link
Contributor

@sakshibobade21 sakshibobade21 commented Mar 11, 2022

Proposed changes

PR attempts to make requests to ZSS w/o any loopbacks to the App server.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Change in a documentation
  • Refactor the code
  • Chore, repository cleanup, updates the dependencies.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

PR Checklist

Please delete options that are not relevant.

  • If the changes in this PR are meant for the next release / mainline, this PR targets the "staging" branch.
  • My code follows the style guidelines of this project (see: Contributing guideline)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • New and existing unit tests pass locally with my changes
  • video or image is included if visual changes are made
  • Relevant update to CHANGELOG.md
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works, or describe a test method below

Testing

Further comments

lib/webapp.js Outdated
req._body = options.body;
req.body = options.body;
req._body = JSON.parse(options.body);
req.body = JSON.parse(options.body);
Copy link
Member

Choose a reason for hiding this comment

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

This has several problems.

  1. if you parse and its not json, you will throw an exception
  2. options.body type detection is already done around line 913
  3. line 923 does JSON.stringify(), so this just reverses it. Choose one or the other.
  4. isn't stringify better since thats what the network does? what issue is this solving?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, stringify is better.
But Robert's team had created the test plugins to reproduce few errors.
And one of the errors occurred because they were accepting the parsed JSON body.

And hence I used JSON.parse() only for the requests that are routed internally.
So we still need to do JSON.stringify() at line 923 for other requests.

Copy link
Member

Choose a reason for hiding this comment

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

OK, thank you for the explanation. A try-catch is still needed however because the body might not be json! If the body is a string, boolean, number... this will not work for other cases. Please check headers["Content-Type"] that was set in 923 or just optimistically try and then catch by saying that well, its not json I guess.

Also a code comment about why you're doing this will be great for the future when we wonder why it is the way it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you.
Please let me know if the changes looks good to you or it's still more safer to use the try catch instead of if else.

lib/webapp.js Outdated
req._body = options.body;
req.body = options.body;
req._body = JSON.parse(options.body);
req.body = JSON.parse(options.body);
Copy link
Member

Choose a reason for hiding this comment

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

OK, thank you for the explanation. A try-catch is still needed however because the body might not be json! If the body is a string, boolean, number... this will not work for other cases. Please check headers["Content-Type"] that was set in 923 or just optimistically try and then catch by saying that well, its not json I guess.

Also a code comment about why you're doing this will be great for the future when we wonder why it is the way it is.

@1000TurquoisePogs
Copy link
Member

Needs DCO fix.

@1000TurquoisePogs 1000TurquoisePogs merged commit 5f9005c into v1.x/staging Apr 4, 2022
@1000TurquoisePogs 1000TurquoisePogs deleted the bugfix/update-routing branch April 20, 2022 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants