Skip to content

Commit

Permalink
If the request store is empty, generate an empty Object response (#332)
Browse files Browse the repository at this point in the history
* If the request store is empty, generate an empty Object response

* Don't fail if prefs is null

* Don't return null if the object doesn't contain any keys.  Instead, return an empty WritableMap

* Unused import
  • Loading branch information
samgiles authored Nov 18, 2016
1 parent 9cb39c9 commit 1eb7d6e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 2 additions & 3 deletions android/app/src/main/java/org/mozilla/magnet/api/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ public static WritableMap jsonToWritableMap(JSONObject jsonObject) {
return null;
}


Iterator<String> iterator = jsonObject.keys();
if (!iterator.hasNext()) {
return null;
return writableMap;
}

while (iterator.hasNext()) {
Expand Down Expand Up @@ -155,4 +154,4 @@ public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) {

return writableArray;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ class ApiPreferences extends Api {
*/
@Override
public void get(String aPath, Callback aCallback) {
aCallback.resolve(getCache().getJsonObject(PREFERENCES_STORE_KEY));
JSONObject json = getCache().getJsonObject(PREFERENCES_STORE_KEY);

if (json == null) {
json = new JSONObject();
}

aCallback.resolve(json);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class App extends React.Component {
debug('inflate user flags');
return api.get('preferences')
.then(prefs => {
Object.keys(prefs ).forEach(key => {
Object.keys(prefs).forEach(key => {
debug('got user flag', key, prefs[key]);
const value = parseBoolean(prefs[key]);
if (value == null) return;
Expand Down

0 comments on commit 1eb7d6e

Please sign in to comment.