jossef/requests

crash in getStoredCookies, calling fromJson with null

sgehrman opened this issue · 0 comments

Exception has occurred.
NoSuchMethodError (NoSuchMethodError: The getter 'length' was called on null.
Receiver: null
Tried calling: length)

static Future<Map<String, String>> getStoredCookies(String hostname) async {
    try {
      String hostnameHash = Common.hashStringSHA256(hostname);
      String cookiesJson = await Common.storageGet('cookies-$hostnameHash');


   // first launch cookiesJson is null, but you are calling fromJson below will null


      var cookies = Common.fromJson(cookiesJson);
      return Map<String, String>.from(cookies);
    } catch (e) {
      log.shout(
          "problem reading stored cookies. fallback with empty cookies $e");
      return Map<String, String>();
    }
  }