Browse Source

add error catching example

http2
Vsevolod Strukchinsky 9 years ago
parent
commit
f4cf6c7b44
  1. 13
      readme.md

13
readme.md

@ -36,10 +36,15 @@ got('todomvc.com', (error, body, response) => {
}); });
// Promise mode // Promise mode
got('todomvc.com').then(response => { got('todomvc.com')
console.log(response.body); .then(response => {
//=> '<!doctype html> ...' console.log(response.body);
}); //=> '<!doctype html> ...'
})
.catch(error => {
console.log(error.response.body);
//=> 'Internal server error ...'
});
// Stream mode // Stream mode
got.stream('todomvc.com').pipe(fs.createWriteStream('index.html')); got.stream('todomvc.com').pipe(fs.createWriteStream('index.html'));

Loading…
Cancel
Save