Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Handling syntax error while parsing HTML response #18
Conversation
| self.emit('log', result); | ||
| if (callback) { | ||
| callback(null, result); | ||
| if(body && res.statusCode.toString() === '200'){ |
mchaudhary
Oct 31, 2017
We should check for non 200 code and log the message.
We should check for non 200 code and log the message.
Shwetajain148
Nov 2, 2017
Author
@mchaudhary, Here if the returned response code is 200 then the body contains {"response" : "ok"} which then get parsed normally. Now If the returned response code is other than 200 and in HTML format as I created a scenario in which I was getting status code 503 "Service Unavailable" then the library breaks to parse the HTML format.
I am not able to check with other server error codes like 500, 501 and 504 etc to see in what format they are returning the response and other error codes in 400 series like I tested with 403(wrong token) and 404(Not found) but in both the cases the control did not come to parse the body object and there was nothing in the body.
In the else part, I am also printing the error code with the error message.
@mchaudhary, Here if the returned response code is 200 then the body contains {"response" : "ok"} which then get parsed normally. Now If the returned response code is other than 200 and in HTML format as I created a scenario in which I was getting status code 503 "Service Unavailable" then the library breaks to parse the HTML format.
I am not able to check with other server error codes like 500, 501 and 504 etc to see in what format they are returning the response and other error codes in 400 series like I tested with 403(wrong token) and 404(Not found) but in both the cases the control did not come to parse the body object and there was nothing in the body.
In the else part, I am also printing the error code with the error message.
@mchaudhary @mostlyjason, This PR is to resolve the issue #17.
In this PR, I have put an if condition to check if the body contains some data and not undefined and also parse the body when the response code is 200 OK. When there is some error returned from the server in HTML form in the body and when it goes to parse, it throws a syntax error. So I am checking both the body and the response code to parse the body further.
Please review.