Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Database Insert Error Handling #4004

Merged
merged 5 commits into from
Oct 23, 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
1 change: 0 additions & 1 deletion lib/api/profile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function configure (app, wares, ctx) {
res.json(created.ops);
console.log('Profile created', created);
}

});
});

Expand Down
5 changes: 5 additions & 0 deletions lib/authorization/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ function init (env, ctx) {
obj.created_at = (new Date()).toISOString();
}
collection.insert(obj, function (err, doc) {
if (err != null && err.message) {
console.log('Data insertion error', err.message);
fn(err.message, null);
return;
}
storage.reload(function loaded() {
fn(null, doc.ops);
});
Expand Down
5 changes: 5 additions & 0 deletions lib/server/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ function storage (env, ctx) {
function create (obj, fn) {
obj.created_at = (new Date( )).toISOString( );
api().insert(obj, function (err, doc) {
if (err != null && err.message) {
console.log('Activity data insertion error', err.message);
fn(err.message, null);
return;
}
fn(null, doc.ops);
});
}
Expand Down
5 changes: 5 additions & 0 deletions lib/server/devicestatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ function storage (collection, ctx) {
obj.created_at = (new Date()).toISOString();
}
api().insert(obj, function (err, doc) {
if (err != null && err.message) {
console.log('Error inserting the device status object', err.message);
fn(err.message, null);
return;
}
fn(null, doc.ops);
ctx.bus.emit('data-received');
});
Expand Down
5 changes: 5 additions & 0 deletions lib/server/food.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ function storage (env, ctx) {
function create (obj, fn) {
obj.created_at = (new Date( )).toISOString( );
api().insert(obj, function (err, doc) {
if (err != null && err.message) {
console.log('Data insertion error', err.message);
fn(err.message, null);
return;
}
fn(null, doc.ops);
});
}
Expand Down
12 changes: 12 additions & 0 deletions lib/server/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ function init (env, ctx, server) {
// if not found create new record
console.log(LOG_DEDUP + 'Adding new record');
ctx.store.collection(collection).insert(data.data, function insertResult (err, doc) {
if (err != null && err.message) {
console.log('treatments data insertion error: ', err.message);
return;
}
if (callback) {
callback(doc.ops);
}
Expand Down Expand Up @@ -367,13 +371,21 @@ function init (env, ctx, server) {
}
});
ctx.store.collection(collection).insert(data.data, function insertResult (err, doc) {
if (err != null && err.message) {
console.log('devicestatus insertion error: ', err.message);
return;
}
if (callback) {
callback(doc.ops);
}
ctx.bus.emit('data-received');
});
} else {
ctx.store.collection(collection).insert(data.data, function insertResult (err, doc) {
if (err != null && err.message) {
console.log(data.collection + ' insertion error: ', err.message);
return;
}
if (callback) {
callback(doc.ops);
}
Expand Down