-
Notifications
You must be signed in to change notification settings - Fork 36
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
Conversation
lib/webapp.js
Outdated
req._body = options.body; | ||
req.body = options.body; | ||
req._body = JSON.parse(options.body); | ||
req.body = JSON.parse(options.body); |
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 has several problems.
- if you parse and its not json, you will throw an exception
- options.body type detection is already done around line 913
- line 923 does JSON.stringify(), so this just reverses it. Choose one or the other.
- isn't stringify better since thats what the network does? what issue is this solving?
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, 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.
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.
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.
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.
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); |
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.
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.
Needs DCO fix. |
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.
PR Checklist
Please delete options that are not relevant.
Testing
Further comments