Node.js and jsdom - unable to detect that http 500 error was received?

I am using jsdom with node.js and I am trying to get it to indicate some signs that an HTTP error has occurred. I installed a test server that simply returns the http 500 header for all requests, but when I try to download it using jsdom, jsdom does not throw any errors and does not seem to provide me any information that would identify that the http 500 error was returned. What is the best way to detect http 500 error?

+4
source share
1 answer

It seems to me that jsdom does not check status codes. 500 status codes are not considered HTTP Node module errors, so they are considered the correct jsdom response.

I suggest you first check the status code before using jsdom and pass jsdom to the body of your response, i.e.:

var jsdom = require('jsdom').jsdom; var request = require('request'); //jsdom already uses request* request("http://www.google.com/", function (err, response, body) { if (!err && response.statusCode == 200) { jsdom.env(body, function (errors, window) { // your code }); } }); 

[*] Request module: https://github.com/mikeal/request

+8
source

Source: https://habr.com/ru/post/1440207/


All Articles