Skip to content

Commit

Permalink
Trap some error instances for DB (#1746)
Browse files Browse the repository at this point in the history
* Also add a copy of dev DB in both clean state and dirty state. No user/pass included ... currently leave that up to end collaboration since handled via environment variable.

Applies to #1745 #37

Refs:
* `mongorestore --gzip --db openuserjs_devel --archive=./dev/devDBdirty.gz`
* `mongodump --gzip --db openuserjs_devel --archive=./dev/devDBclean.gz`
* `CONNECT_STRING=mongodb://127.0.0.1:27017/openuserjs_devel`

Auto-merge
  • Loading branch information
Martii committed Aug 28, 2020
1 parent 6c1036b commit 9afd03b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ lib-cov
*.out
*.pid
*.gz
!dev/devDBclean.gz
!dev/devDBdirty.gz

pids
logs
Expand Down
9 changes: 7 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ app.set('securePort', process.env.SECURE_PORT || null);
mongoose.connect(connectStr, dbOptions);

// Trap a few events for MongoDB
db.on('error', function () {
console.error(colors.red('MongoDB connection error'));
db.on('error', function (aErr) {
console.error( colors.red( [
'MongoDB connection error',
aErr.message,
'Terminating app'
].join('\n')));
process.exit(1); // NOTE: Watchpoint
});

db.once('open', function () {
Expand Down
Binary file added dev/devDBclean.gz
Binary file not shown.
Binary file added dev/devDBdirty.gz
Binary file not shown.
18 changes: 16 additions & 2 deletions libs/repoManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var statusError = require('../libs/debug').statusError;

//--- Dependency inclusions
var util = require('util');

var colors = require('ansi-colors');

//--- Model inclusions
var Sync = require('../models/sync').Sync;
Expand All @@ -32,7 +32,21 @@ var clientId = null;
var clientKey = null;

Strategy.findOne({ name: 'github' }, function (aErr, aStrat) {
// WARNING: No err handling
if (aErr) {
console.error( aErr.message );
process.exit(1);
return;
}

if (!aStrat) {
console.error( colors.red( [
'Default GitHub Strategy document not found in DB',
'Terminating app'
].join('\n')));

process.exit(1);
return;
}

clientId = aStrat.id;
clientKey = aStrat.key;
Expand Down

0 comments on commit 9afd03b

Please sign in to comment.