Promise chain

by Cristi Salcescu

JavaScript

getTodos()
  .then(toJson)
  .then(getTopPriority)
  .then(renderTodos)
  .catch(handleError);
  
function getTodos(){
	let url = "https://jsonplaceholder.typicode.com/todos";
	return fetch(url);
}

function toJson(response){
  return response.json();
}

function getTopPriority(todos){
	return todos.filter(todo => !todo.completed);
}

function renderTodos(todos){
	console.dir(todos);
}
 
function handleError(error){
  console.error("There was an error :" + error.status);
}