tuanpmt / react-native-smartconfig

A React Native module for ESP8266 Smartconfig
128 stars 65 forks source link

Unhandled promise rejection #4

Open hdrut opened 6 years ago

hdrut commented 6 years ago

I had to add a try-catch block in this module and throw an exception to handle case when Smartconfig is not successful :

        try{
          for (IEsptouchResult resultInList : result) {
            if(!resultInList.isCancelled() && resultInList.getBssid() != null) {
              WritableMap map = Arguments.createMap();
              map.putString("bssid", resultInList.getBssid());
              map.putString("ipv4", resultInList.getInetAddress().getHostAddress());
              ret.pushMap(map);
              resolved = true;                  
              if (!resultInList.isSuc()) {
                //Log.d(TAG, "Not successful!");
                break;                    
              }                
            }
          }
          if(resolved) {
            Log.d(TAG, "Success in Smartconfig run");
            promise.resolve(ret);
          } else {
            //Log.d(TAG, " " + resolved);
            throw new Exception();
          }
        } catch(Exception e){ 
            Log.d(TAG, "Error, Smartconfig could not complete!");
            promise.reject("new Exception()", e);
          }