How to get Readable error response from JavaScript Fetch API?

Since the text is hidden inside promise within response object, it needs to be handled like a promise to see it.

fetch(bla)
    .then(res => {
      if(!res.ok) {
        return res.text().then(text => { throw new Error(text) })
       }
      else {
       return res.json();
     }    
    })
    .catch(err => {
       console.log('caught it!',err);
    });
    

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)