A
A
Alexander Koshelev2018-06-10 00:28:17
Node.js
Alexander Koshelev, 2018-06-10 00:28:17

How to get a response in the form of an html page for a post request?

Good afternoon, guys, I use node-fetch and make a request to the site page, namely, I make a request for authorization, everything is sent normally, etc., but the response (in the network in the developer console in the browser) is issued in the form of html and not json.
Here is part of my code when responding as json

.then((res) => {
   console.log(res);
    console.log("___________________________________");
    console.log(res.text());
   return res.json();
})
   .then((json) => {
    console.log(json);
    console.log("___________________________________");
  })

How can I properly organize the html output to check the authorization was successful or there was an error
PS how to determine the error I understood it is in one of the html lines, but how to display it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-06-14
@atcrew

Usually, authorization returns an error 401 on error, if this is the case for you, then node-fetch allows the following (code from the docks)
if authorization does not give an error on error, but returns stupidly Html (200), then html will have to be parsed in order to find out whether an error has occurred or not .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question