Fix server crashing when there was MongoDB connection error
This commit is contained in:
parent
ba0fa15e0a
commit
afc439f19a
1 changed files with 4 additions and 4 deletions
|
@ -41,7 +41,7 @@ function generateUniqueShortenedURLID(db, callback) {
|
||||||
var id = generateShortenedURLID();
|
var id = generateShortenedURLID();
|
||||||
db.collection("urls").find({id: id}).toArray(function(err, result) {
|
db.collection("urls").find({id: id}).toArray(function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
db.close();
|
if(db.close) db.close();
|
||||||
callServerError(500, err);
|
callServerError(500, err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ if (href.match(/^\/admin\/?$/)) {
|
||||||
connectMongo(function(db) {
|
connectMongo(function(db) {
|
||||||
db.collection("urls").find({url: purl}).toArray(function(err, result) {
|
db.collection("urls").find({url: purl}).toArray(function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
db.close();
|
if(db.close) db.close();
|
||||||
callServerError(500, err);
|
callServerError(500, err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ if (href.match(/^\/admin\/?$/)) {
|
||||||
generateUniqueShortenedURLID(db, function(id) {
|
generateUniqueShortenedURLID(db, function(id) {
|
||||||
db.collection("urls").insertOne({id: id, url: purl}, function(err, dbres) {
|
db.collection("urls").insertOne({id: id, url: purl}, function(err, dbres) {
|
||||||
if (err) {
|
if (err) {
|
||||||
db.close();
|
if(db.close) db.close();
|
||||||
callServerError(500, err);
|
callServerError(500, err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ if (href.match(/^\/admin\/?$/)) {
|
||||||
connectMongo(function(db) {
|
connectMongo(function(db) {
|
||||||
db.collection("urls").find({id: id}).toArray(function(err, result) {
|
db.collection("urls").find({id: id}).toArray(function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
db.close();
|
if(db.close) db.close();
|
||||||
callServerError(500, err);
|
callServerError(500, err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue