소스 검색

Update README with proper status code handling

Gui Meira 6 년 전
부모
커밋
393c668c38
1개의 변경된 파일12개의 추가작업 그리고 8개의 파일을 삭제
  1. 12
    8
      README.md

+ 12
- 8
README.md 파일 보기

@@ -192,16 +192,20 @@ RNFetchBlob.fetch('GET', 'http://www.example.com/images/img1.png', {
192 192
     Authorization : 'Bearer access-token...',
193 193
     // more headers  ..
194 194
   })
195
-  // when response status code is 200
196 195
   .then((res) => {
197
-    // the conversion is done in native code
198
-    let base64Str = res.base64()
199
-    // the following conversions are done in js, it's SYNC
200
-    let text = res.text()
201
-    let json = res.json()
202
-
196
+    let status = res.info().status;
197
+    
198
+    if(status == 200) {
199
+      // the conversion is done in native code
200
+      let base64Str = res.base64()
201
+      // the following conversions are done in js, it's SYNC
202
+      let text = res.text()
203
+      let json = res.json()
204
+    } else {
205
+      // handle other status codes
206
+    }
203 207
   })
204
-  // Status code is not 200
208
+  // Something went wrong:
205 209
   .catch((errorMessage, statusCode) => {
206 210
     // error handling
207 211
   })