Skip to content

Commit

Permalink
Handle invalid responses correctly when they are not JSON (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Th3Shadowbroker committed Oct 24, 2019
1 parent 751d0a6 commit a90b8c7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions svc/api/Timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ class Timer {
res => {
res.on('data', (chunk) => data += chunk);
res.on('end', () => {
let parsedData = JSON.parse(data);
mcache.put(cacheKey, parsedData, config.get('cacheTimeout') * 1000);
resolve(parsedData);
try
{
let parsedData = JSON.parse(data);
mcache.put(cacheKey, parsedData, config.get('cacheTimeout') * 1000);
resolve(parsedData);
} catch (e) {
reject(e);
}
});
}
);
Expand Down

0 comments on commit a90b8c7

Please sign in to comment.