Skip to content

Commit 549bb5d

Browse files
Merge pull request #18 from JDragovichAlertLogic/catch-raw-string-errors
fix error handling to catch raw string errors
2 parents c209634 + b566894 commit 549bb5d

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

master.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,13 @@ class AlAzureMaster {
365365
function(errStatus) {
366366
var status;
367367
if (errStatus) {
368-
master._azureContext.log.warn('Health check failed with', errStatus.details);
369-
status = errStatus;
368+
if(typeof errStatus === 'string'){
369+
master._azureContext.log.warn('Health check failed with: ', errStatus);
370+
status = master.errorStatusFmt('ALAZU000004', errStatus);
371+
} else {
372+
master._azureContext.log.warn('Health check failed with', errStatus.details);
373+
status = errStatus;
374+
}
370375
} else {
371376
status = {
372377
status: 'ok',

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alertlogic/al-azure-collector-js",
3-
"version": "1.1.3",
3+
"version": "1.2.0",
44
"description": "Alert Logic Azure Collector Common Library",
55
"license": "MIT",
66
"repository": {
@@ -28,7 +28,7 @@
2828
"sinon": "^7.2.3"
2929
},
3030
"dependencies": {
31-
"@alertlogic/al-collector-js": "^1.1.2",
31+
"@alertlogic/al-collector-js": "^1.3.0",
3232
"async": "^2.6.1",
3333
"azure": "^2.3.1-preview",
3434
"parse-key-value": "^1.0.0",

test/collector_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ describe('Collector tests', function() {
6464

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

7171
return new Promise(function(resolve, reject){
@@ -106,8 +106,8 @@ describe('Collector tests', function() {
106106

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

113113
return new Promise(function(resolve, reject){

test/master_test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,37 @@ describe('Master tests', function() {
560560
});
561561
});
562562

563+
it('Verify checkin with custom health-check error that returns a raw string', function(done) {
564+
var customHealthFuns = [
565+
function(m, callback) {
566+
return callback(null);
567+
},
568+
function(m, callback) {
569+
return callback("A Raw String Error");
570+
}
571+
];
572+
var master = new AlAzureMaster(mock.DEFAULT_FUNCTION_CONTEXT, 'ehub', '1.0.0', customHealthFuns);
573+
master.checkin('2017-12-22T14:31:39', function(err){
574+
if (err) console.log(err);
575+
const expectedCheckin = {
576+
body: {
577+
version: '1.0.0',
578+
app_tenant_id: 'tenant-id',
579+
collection_stats: { 'log': { 'bytes': 10, 'events': 15 } },
580+
host_id: 'existing-host-id',
581+
source_id: 'existing-source-id',
582+
statistics: [{ 'Master': { 'errors': 0, 'invocations': 2 } }, { 'Collector': { 'errors': 1, 'invocations': 10 } }, { 'Updater': { 'errors': 0, 'invocations': 0 } }],
583+
status: 'error',
584+
details: ["A Raw String Error"],
585+
error_code: 'ALAZU000004'
586+
}
587+
};
588+
const expectedUrl = '/azure/ehub/checkin/subscription-id/kktest11-rg/kktest11-name';
589+
sinon.assert.calledWithMatch(fakePost, expectedUrl, expectedCheckin);
590+
done();
591+
});
592+
});
593+
563594
it('Verify checkin with custom health-check error', function(done) {
564595
var customHealthFuns = [
565596
function(m, callback) {

0 commit comments

Comments
 (0)