1fetch('http://some-site.com/api/some.json')
2 .then(function(response) { // first then()
3 if(response.ok)
4 {
5 return response.text();
6 }
7
8 throw new Error('Something went wrong.');
9 })
10 .then(function(text) { // second then()
11 console.log('Request successful', text);
12 })
13 .catch(function(error) { // catch
14 console.log('Request failed', error);
15 });
16