Check not null before attempting format

This commit is contained in:
Alicia Sykes
2017-12-31 22:23:24 +00:00
parent da57714dc3
commit 1d80ba6e60

View File

@@ -13,6 +13,7 @@ formatText = (tweetBody) ->
formatData = (data) -> formatData = (data) ->
results = [] results = []
if data == null then return []
for key in Object.keys data for key in Object.keys data
category = key.charAt(0).toUpperCase()+key.split('_')[0].slice(1) category = key.charAt(0).toUpperCase()+key.split('_')[0].slice(1)
results.push name: category, items: data[key] results.push name: category, items: data[key]
@@ -20,6 +21,7 @@ formatData = (data) ->
router.post '/', (req, res) -> router.post '/', (req, res) ->
entityExtraction formatText(req.body.text), hpKey, (data) -> entityExtraction formatText(req.body.text), hpKey, (data) ->
console.log data
res.json formatData data res.json formatData data
module.exports = router module.exports = router