JS

HOW TO DEBUG JS FETCH

(quick guide & example)

console.log("Fetch start"); fetch("URL") .then(res => {   console.log(res);   return res.text(); }) .then(txt => console.log(txt)) .catch(err => console.error(err));

LOG ALL RESPONSES

01

WHICH STAGE DID IT GO WRONG?

02

BEFORE FETCH - "Fetch start" is not even logged. Something is wrong with your pre-processing. 

DURING FETCH - Use console.log (res.status) to get server HTTP response code. Should be 200 (OK).

DURING FETCH - Turn on server side error reporting, console.log(txt) will show whatever server responded; Including server side script error messages.

AFTER FETCH - Not "fetch error". But if not getting intended results, your processing is wrong somewhere.