mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-03-12 23:40:00 +00:00
add error handler for resources
This commit is contained in:
parent
6d664213c5
commit
fec6633a7a
@ -9,7 +9,7 @@ catchRev:
|
|||||||
|
|
||||||
notify:
|
notify:
|
||||||
on:
|
on:
|
||||||
- done
|
# - done
|
||||||
# - error
|
# - error
|
||||||
- change
|
- change
|
||||||
to:
|
to:
|
||||||
|
@ -7,7 +7,7 @@ var Steppy = require('twostep').Steppy,
|
|||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
var resource = app.dataio.resource('builds');
|
var resource = app.dataio.resource('builds');
|
||||||
|
|
||||||
resource.use('readAll', function(req, res) {
|
resource.use('readAll', function(req, res, next) {
|
||||||
Steppy(
|
Steppy(
|
||||||
function() {
|
function() {
|
||||||
var findParams = _(req.data).pick('offset', 'limit');
|
var findParams = _(req.data).pick('offset', 'limit');
|
||||||
@ -19,13 +19,11 @@ module.exports = function(app) {
|
|||||||
function(err, builds) {
|
function(err, builds) {
|
||||||
res.send(builds);
|
res.send(builds);
|
||||||
},
|
},
|
||||||
function(err) {
|
next
|
||||||
console.log(err.stack || err)
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
resource.use('read', function(req, res) {
|
resource.use('read', function(req, res, next) {
|
||||||
Steppy(
|
Steppy(
|
||||||
function() {
|
function() {
|
||||||
var findParams = {};
|
var findParams = {};
|
||||||
@ -35,9 +33,7 @@ module.exports = function(app) {
|
|||||||
function(err, build) {
|
function(err, build) {
|
||||||
res.send(build[0]);
|
res.send(build[0]);
|
||||||
},
|
},
|
||||||
function(err) {
|
next
|
||||||
console.log(err.stack || err)
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
9
resources/errorHandler.js
Normal file
9
resources/errorHandler.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = function(err, req, res, next) {
|
||||||
|
console.error(
|
||||||
|
'Error is occurred during requesting ' +
|
||||||
|
req.resource.namespace.name + ' ' + req.action + ':',
|
||||||
|
err.stack || err
|
||||||
|
);
|
||||||
|
};
|
@ -1,9 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('underscore');
|
var _ = require('underscore'),
|
||||||
|
errorHandler = require('./errorHandler');
|
||||||
|
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
_(['builds', 'projects']).each(function(resource) {
|
_(['builds', 'projects']).each(function(resource) {
|
||||||
require('./' + resource)(app);
|
var resource = require('./' + resource)(app);
|
||||||
|
resource.use(errorHandler);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,8 @@ var Steppy = require('twostep').Steppy,
|
|||||||
Distributor = require('../lib/distributor').Distributor,
|
Distributor = require('../lib/distributor').Distributor,
|
||||||
db = require('../db'),
|
db = require('../db'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
fs = require('fs');
|
fs = require('fs'),
|
||||||
|
utils = require('../lib/utils');
|
||||||
|
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
|
|
||||||
@ -58,9 +59,7 @@ module.exports = function(app) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on('end', callback)
|
.on('end', callback)
|
||||||
.on('error', function(err) {
|
.on('error', utils.logErrorCallback);
|
||||||
console.log(err.stack || err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
buildDataResourcesHash[build.id] = buildDataResource;
|
buildDataResourcesHash[build.id] = buildDataResource;
|
||||||
};
|
};
|
||||||
@ -97,9 +96,7 @@ module.exports = function(app) {
|
|||||||
writeStreamsHash[filePath] = fs.createWriteStream(
|
writeStreamsHash[filePath] = fs.createWriteStream(
|
||||||
getBuildLogPath(build.id), {encoding: 'utf8'}
|
getBuildLogPath(build.id), {encoding: 'utf8'}
|
||||||
);
|
);
|
||||||
writeStreamsHash[filePath].on('error', function(err) {
|
writeStreamsHash[filePath].on('error', utils.logErrorCallback);
|
||||||
console.error(err.stack || err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// TODO: close ended files
|
// TODO: close ended files
|
||||||
writeStreamsHash[filePath].write(data);
|
writeStreamsHash[filePath].write(data);
|
||||||
@ -117,9 +114,7 @@ module.exports = function(app) {
|
|||||||
distributor.run({
|
distributor.run({
|
||||||
projectName: projectName,
|
projectName: projectName,
|
||||||
initiator: {type: 'user'}
|
initiator: {type: 'user'}
|
||||||
}, function(err, build) {
|
}, utils.logErrorCallback);
|
||||||
console.log('>>> err, build = ', err && err.stack || err, build);
|
|
||||||
});
|
|
||||||
res.send();
|
res.send();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user