From 393c668c38a152c891cd09fd121edc4c258f6335 Mon Sep 17 00:00:00 2001 From: Gui Meira Date: Wed, 30 May 2018 14:11:59 -0300 Subject: [PATCH] Update README with proper status code handling --- README.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6b4cfc75b..44ba5ab7c 100644 --- a/README.md +++ b/README.md @@ -192,16 +192,20 @@ RNFetchBlob.fetch('GET', 'http://www.example.com/images/img1.png', { Authorization : 'Bearer access-token...', // more headers .. }) - // when response status code is 200 .then((res) => { - // the conversion is done in native code - let base64Str = res.base64() - // the following conversions are done in js, it's SYNC - let text = res.text() - let json = res.json() - + let status = res.info().status; + + if(status == 200) { + // the conversion is done in native code + let base64Str = res.base64() + // the following conversions are done in js, it's SYNC + let text = res.text() + let json = res.json() + } else { + // handle other status codes + } }) - // Status code is not 200 + // Something went wrong: .catch((errorMessage, statusCode) => { // error handling })