From f4cf6c7b44d047d505ed1fdf3a4e361b743bdfc2 Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Tue, 20 Oct 2015 00:22:57 +0500 Subject: [PATCH] add error catching example --- readme.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 078893d..43ea0f6 100644 --- a/readme.md +++ b/readme.md @@ -36,10 +36,15 @@ got('todomvc.com', (error, body, response) => { }); // Promise mode -got('todomvc.com').then(response => { - console.log(response.body); - //=> ' ...' -}); +got('todomvc.com') + .then(response => { + console.log(response.body); + //=> ' ...' + }) + .catch(error => { + console.log(error.response.body); + //=> 'Internal server error ...' + }); // Stream mode got.stream('todomvc.com').pipe(fs.createWriteStream('index.html'));