Linked Questions

Popular Questions

react-native fail to handle error in try catch block

Asked by At

i am trying send image with fetch() function. Showing red screen and. 'no such file or directory' error before send data. try catch block is not handling this error.

019-02-11 22:35:00.375 [error][tid:com.facebook.react.NetworkingQueue][RCTNetworking.mm:272] Error processing request body: Error Domain=NSCocoaErrorDomain Code=260 "The file “5325CBBA-340E-4227-AE17-5D42021DF648.jpg” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/myuser/Library/Developer/CoreSimulator/Devices/9362AC50-7C82-4C8D-B686-39A6718CBA5F/data/Containers/Data/Application/64CD29E3-2BD9-4D9A-B168-4B12A848889C/Documents/images/5325CBBA-340E-4227-AE17-5D42021DF648.jpg, NSUnderlyingError=0x600003c0a790 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

How to handle this error ?

error screen: https://i.hizliresim.com/bVvqrm.png

  VeriListele() {

    try {
      db.transaction((tx) => {
        tx.executeSql("select * from " + TABLO_DATA + " where " + ROW_GONDERILDI_ + "=0", [], (tx, results) => {
          console.log("Query completed2");

          // Get rows with Web SQL Database spec compliance.
          console.log(results.rows);
          var len = results.rows.length;
          const data = new FormData();
          for (let i = 0; i < len; i++) {
            try {
              let row = results.rows.item(i);
              console.log(row);
              var FotoString='';
              if (row.resim1!='' && row.resim1!='undefined') {
                var resimjson=JSON.parse(row.resim1);
                FotoString+='&photo[]='+row.resim1;
                data.append('photo1[]', {
                  uri: resimjson.uri,
                  type: resimjson.type, // or photo.type
                  name: 'photo'
                });
              }
              if (row.resim2!='' && row.resim2!='undefined') {
                FotoString+='&photo[]='+row.resim2;
                var resimjson=JSON.parse(row.resim2);
                data.append('photo1[]', {
                  uri: resimjson.uri,
                  type:resimjson.type, // or photo.type
                  name: 'photo'
                });
              }
              if (row.resim3!='' && row.resim3!='undefined') {
                FotoString+='&photo[]='+row.resim3;
                var resimjson=JSON.parse(row.resim3);
                data.append('photo1[]', {
                  uri: resimjson.uri,
                  type: resimjson.type, // or photo.type
                  name: 'photo'
                });
              }
              if (row.resim4!='' && row.resim4!='undefined') {
                FotoString+='&photo[]='+row.resim4;
                var resimjson=JSON.parse(row.resim4);
                data.append('photo1[]', {
                  uri:resimjson.uri,
                  type: resimjson.type, // or photo.type
                  name: 'photo'
                });
              }
              if (row.video!='' && row.video!='undefined') {
                FotoString+='&video[]='+row.video;
                var resimjson=JSON.parse(row.video);
                data.append('video1[]', {
                  uri: resimjson.uri,
                  type: resimjson.type, // or photo.type
                  name: 'video'
                });
              }
              try {

              } catch (error) {

              }


          data.append('api_token', Global.GToken); // you can append anyone.
          data.append('resid', row.id); // you can append anyone.

          data.append('additional', row.ek_aciklama); // you can append anyone.

          data.append('issue_date', row.tarih.split(' ')[0]); // you can append anyone.
          try {
            fetch("https://myapi.com/add", {
              method: 'post',
              body: data
            }).then(function(response){
              console.log(response);
             var responseJson=JSON.parse(response._bodyText)
            //  console.log();

              console.log(response);
            //  console.log(responseJson);
            //  console.log(responseJson);
              if (responseJson.sonuc == 1) {
                db.transaction((tx1) => {
                  console.log(row.id);
                  tx1.executeSql("update " + TABLO_DATA + " set gonderildi=1 where id=" + row.id + "");
                });


              } else if (responseJson.sonuc==0) {
                console.log('basarisiz');
                db.transaction((tx1) => {
                 // tx1.executeSql("update " + TABLO_DATA + " set gonderildi=1 where id=" + row.id + "");
                });
              }
            }).catch(error =>console.log(error) )
          } catch (error) {
            console.log('bb');
          }




            } catch (error) {
              console.log('ss');
            }

          }
        });
      });

    } catch (error) {
      console.log('dd');
    }
    //  const Veriler = await AsyncStorage.getItem(‘products’)
    }

Related Questions