From ff822a9ab97259b0483f7d558d229a223aa42e16 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Wed, 13 Feb 2019 05:54:06 +1100 Subject: [PATCH] Update handling of incomplete OneDrive JSON responses (#375) * Re-order handling of response JSON to ensure that 'id' key element is always checked for. * Print errors when there is an issue with saveItem & articulate why --- src/sync.d | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/sync.d b/src/sync.d index 4a7b0c9e..bd42f747 100644 --- a/src/sync.d +++ b/src/sync.d @@ -1814,21 +1814,28 @@ final class SyncEngine response = onedrive.updateById(driveId, id, data, nullTag); } } - // Check if the response JSON has an 'id', otherwise makeItem() fails with 'Key not found: id' - if (hasId(response)) { - // save the updated response from OneDrive in the database - saveItem(response); - } + // save the updated response from OneDrive in the database + saveItem(response); } private void saveItem(JSONValue jsonItem) { // jsonItem has to be a valid object if (jsonItem.object()){ - // Takes a JSON input and formats to an item which can be used by the database - Item item = makeItem(jsonItem); - // Add to the local database - itemdb.upsert(item); + // Check if the response JSON has an 'id', otherwise makeItem() fails with 'Key not found: id' + if (hasId(jsonItem)) { + // Takes a JSON input and formats to an item which can be used by the database + Item item = makeItem(jsonItem); + // Add to the local database + itemdb.upsert(item); + } else { + // log error + log.error("ERROR: OneDrive response missing required 'id' element:"); + log.error("ERROR: ", jsonItem); + } + } else { + // log error + log.error("ERROR: OneDrive response not a valid JSON object"); } }