From 43d9f243d8d0f049a7e39600dcb105b3a2b09e27 Mon Sep 17 00:00:00 2001 From: Willem Date: Mon, 14 Mar 2016 00:42:10 +0100 Subject: [PATCH] added error on parse + obj --- README.md | 1 + es5-ff-spa-loader.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e103b1d..438f76b 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,7 @@ Add unit tests for any new or changed functionality. Lint and test your code. * refined css so question/loader/error are equal. * Added response header check support. * Added json accept header on assets resources list. +* Added cb errors on assets resources json parse + result obj. ### 0.1.1 * Moved websql delete timeout to cleanServerlUrl for faster boot. diff --git a/es5-ff-spa-loader.js b/es5-ff-spa-loader.js index c7968b7..0926514 100644 --- a/es5-ff-spa-loader.js +++ b/es5-ff-spa-loader.js @@ -761,7 +761,22 @@ } return; } - var resources = JSON.parse(httpRequest.responseText).data.resources; + var resources = null; + try { + var responseObject = JSON.parse(httpRequest.responseText); + if (responseObject.data === undefined) { + return cb('No data in json'); + } + if (responseObject.data.resources === undefined) { + return cb('No resources in json'); + } + if (responseObject.data.resources.length === 0) { + return cb('Empty resources in json'); + } + resources = responseObject.data.resources; + } catch (parseError) { + return cb(parseError); + } utilDebug('startLoader resources '+resources.length); var progressBar = createLoaderBar(resources);