Skip to content

Commit

Permalink
Merge pull request #18 from JDragovichAlertLogic/catch-raw-string-errors
Browse files Browse the repository at this point in the history
fix error handling to catch raw string errors
  • Loading branch information
JDragovichAlertLogic authored Jul 3, 2019
2 parents c209634 + b566894 commit 549bb5d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
9 changes: 7 additions & 2 deletions master.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,13 @@ class AlAzureMaster {
function(errStatus) {
var status;
if (errStatus) {
master._azureContext.log.warn('Health check failed with', errStatus.details);
status = errStatus;
if(typeof errStatus === 'string'){
master._azureContext.log.warn('Health check failed with: ', errStatus);
status = master.errorStatusFmt('ALAZU000004', errStatus);
} else {
master._azureContext.log.warn('Health check failed with', errStatus.details);
status = errStatus;
}
} else {
status = {
status: 'ok',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alertlogic/al-azure-collector-js",
"version": "1.1.3",
"version": "1.2.0",
"description": "Alert Logic Azure Collector Common Library",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -28,7 +28,7 @@
"sinon": "^7.2.3"
},
"dependencies": {
"@alertlogic/al-collector-js": "^1.1.2",
"@alertlogic/al-collector-js": "^1.3.0",
"async": "^2.6.1",
"azure": "^2.3.1-preview",
"parse-key-value": "^1.0.0",
Expand Down
8 changes: 4 additions & 4 deletions test/collector_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ describe('Collector tests', function() {

fakePost = sinon.stub(alcollector.AlServiceC.prototype, 'post').callsFake(
function fakeFn(path, extraOptions) {
assert.equal(extraOptions.headers['Content-Type'], 'alertlogic.com/pass-through');
assert.equal(path, '/data/aicspmsgs');
assert.equal(extraOptions.headers['Content-Type'], 'alertlogic.com/lm3-protobuf');
assert.equal(path, '/data/logmsgs');
assert.equal(expectedBody, extraOptions.body.toString('base64'));

return new Promise(function(resolve, reject){
Expand Down Expand Up @@ -106,8 +106,8 @@ describe('Collector tests', function() {

fakePost = sinon.stub(alcollector.AlServiceC.prototype, 'post').callsFake(
function fakeFn(path, extraOptions) {
assert.equal(extraOptions.headers['Content-Type'], 'alertlogic.com/pass-through');
assert.equal(path, '/data/aicspmsgs');
assert.equal(extraOptions.headers['Content-Type'], 'alertlogic.com/lm3-protobuf');
assert.equal(path, '/data/logmsgs');
assert.equal(expectedBody, extraOptions.body.toString('base64'));

return new Promise(function(resolve, reject){
Expand Down
31 changes: 31 additions & 0 deletions test/master_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,37 @@ describe('Master tests', function() {
});
});

it('Verify checkin with custom health-check error that returns a raw string', function(done) {
var customHealthFuns = [
function(m, callback) {
return callback(null);
},
function(m, callback) {
return callback("A Raw String Error");
}
];
var master = new AlAzureMaster(mock.DEFAULT_FUNCTION_CONTEXT, 'ehub', '1.0.0', customHealthFuns);
master.checkin('2017-12-22T14:31:39', function(err){
if (err) console.log(err);
const expectedCheckin = {
body: {
version: '1.0.0',
app_tenant_id: 'tenant-id',
collection_stats: { 'log': { 'bytes': 10, 'events': 15 } },
host_id: 'existing-host-id',
source_id: 'existing-source-id',
statistics: [{ 'Master': { 'errors': 0, 'invocations': 2 } }, { 'Collector': { 'errors': 1, 'invocations': 10 } }, { 'Updater': { 'errors': 0, 'invocations': 0 } }],
status: 'error',
details: ["A Raw String Error"],
error_code: 'ALAZU000004'
}
};
const expectedUrl = '/azure/ehub/checkin/subscription-id/kktest11-rg/kktest11-name';
sinon.assert.calledWithMatch(fakePost, expectedUrl, expectedCheckin);
done();
});
});

it('Verify checkin with custom health-check error', function(done) {
var customHealthFuns = [
function(m, callback) {
Expand Down

0 comments on commit 549bb5d

Please sign in to comment.