fetch().then()

by Gustavo

JavaScript

fetch('xhttps://jsonplaceholder.typicode.com/todos/1')
	.then((res) => {
  
  	console.log('Response:', res);
    
    if (!res.ok) {
    	throw new Error(`Error: ${res.status}`)
    }
    
    return res.json();
  	    
  })
  .then((data) => {
  
  	console.log(data.title);
    
  })
  .catch((err) => {
  
   throw new Error(`Error: ${err}`)
   
  })