Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Add exception handler to prevent crash #12

Merged
merged 1 commit into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ router.route('/coordinates/:coordinates')
});
}).then(ary => {
return res.json(ary);
}, {concurrency: 2});
}, {concurrency: 2})
.catch(err => {
console.log(err)
return res.json({error: `Exception: ${err}`})
});
});

module.exports = router;
4 changes: 2 additions & 2 deletions src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pool_countries.on('error', (err, client) => {
exports.search = function(coordinates) {
return new Promise((resolve, reject) => {
pool_countries.connect((err, client, done) => {
if (err) throw err
if (err) return reject(err)
client.query('select iso, name_0, name_1, name_2, ' +
'name_3, name_4, name_5, ' +
'ID_0, ID_1, ID_2, ID_3, ID_4, ID_5 from all_countries_one_table ' +
Expand All @@ -27,7 +27,7 @@ exports.search = function(coordinates) {
')\',4326),4326), all_countries_one_table.geom);', [], (error, res) => {
done()
if (error) {
console.log(error.stack)
return reject(error)
} else {
if (res.rows.length < 1) {
return resolve(
Expand Down