Skip to content

Commit

Permalink
Re-order catch clauses and actually output the suppressed error to co…
Browse files Browse the repository at this point in the history
…nsole
  • Loading branch information
Wedvich committed Aug 23, 2018
1 parent a99c724 commit cb7f2d3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 45 deletions.
28 changes: 13 additions & 15 deletions dist/structured-log-seq-sink.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ function mapLogLevel(logLevel) {
}

function logSuppressedError(reason) {
// if (typeof console !== 'undefined' && console.warn) {
// console.warn('Suppressed error when logging to Seq: ' + reason);
// }
if (typeof console !== 'undefined' && console.warn) {
console.warn('Suppressed error when logging to Seq: ' + reason);
}
}

var SeqSink = function () {
Expand Down Expand Up @@ -95,10 +95,10 @@ var SeqSink = function () {
}

var body = localStorage.getItem(storageKey);
requests[storageKey] = postToSeq(this.url, this.apiKey, this.compact, body).catch(function (reason) {
return _this.suppressErrors ? logSuppressedError(reason) : Promise.reject(reason);
}).then(function () {
requests[storageKey] = postToSeq(this.url, this.apiKey, this.compact, body).then(function () {
return localStorage.removeItem(k);
}).catch(function (reason) {
return _this.suppressErrors ? logSuppressedError(reason) : Promise.reject(reason);
});
}
}
Expand Down Expand Up @@ -170,16 +170,14 @@ var SeqSink = function () {
localStorage.setItem(storageKey, body);
}

return postToSeq(this.url, this.apiKey, this.compact, body, done).catch(function (reason) {
return postToSeq(this.url, this.apiKey, this.compact, body, done).then(function (response) {
return response.json();
}).then(function (json) {
return _this3.updateLogLevel(json);
}).then(function () {
if (storageKey) localStorage.removeItem(storageKey);
}).catch(function (reason) {
return _this3.suppressErrors ? logSuppressedError(reason) : Promise.reject(reason);
}).then(function (response) {
return response && response.json().then(function (json) {
return _this3.updateLogLevel(json);
}).then(function () {
if (storageKey) {
localStorage.removeItem(storageKey);
}
});
});
}
}, {
Expand Down
28 changes: 13 additions & 15 deletions dist/structured-log-seq-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
}

function logSuppressedError(reason) {
// if (typeof console !== 'undefined' && console.warn) {
// console.warn('Suppressed error when logging to Seq: ' + reason);
// }
if (typeof console !== 'undefined' && console.warn) {
console.warn('Suppressed error when logging to Seq: ' + reason);
}
}

var SeqSink = function () {
Expand Down Expand Up @@ -101,10 +101,10 @@
}

var body = localStorage.getItem(storageKey);
requests[storageKey] = postToSeq(this.url, this.apiKey, this.compact, body).catch(function (reason) {
return _this.suppressErrors ? logSuppressedError(reason) : Promise.reject(reason);
}).then(function () {
requests[storageKey] = postToSeq(this.url, this.apiKey, this.compact, body).then(function () {
return localStorage.removeItem(k);
}).catch(function (reason) {
return _this.suppressErrors ? logSuppressedError(reason) : Promise.reject(reason);
});
}
}
Expand Down Expand Up @@ -176,16 +176,14 @@
localStorage.setItem(storageKey, body);
}

return postToSeq(this.url, this.apiKey, this.compact, body, done).catch(function (reason) {
return postToSeq(this.url, this.apiKey, this.compact, body, done).then(function (response) {
return response.json();
}).then(function (json) {
return _this3.updateLogLevel(json);
}).then(function () {
if (storageKey) localStorage.removeItem(storageKey);
}).catch(function (reason) {
return _this3.suppressErrors ? logSuppressedError(reason) : Promise.reject(reason);
}).then(function (response) {
return response && response.json().then(function (json) {
return _this3.updateLogLevel(json);
}).then(function () {
if (storageKey) {
localStorage.removeItem(storageKey);
}
});
});
}
}, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "structured-log-seq-sink",
"version": "0.4.0",
"version": "0.4.1",
"description": "A structured-log plugin that writes log events to Seq.",
"main": "dist/structured-log-seq-sink.js",
"jsnext:main": "dist/structured-log-seq-sink.es6.js",
Expand Down
23 changes: 9 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ function mapLogLevel(logLevel) {
}

function logSuppressedError(reason) {
// if (typeof console !== 'undefined' && console.warn) {
// console.warn('Suppressed error when logging to Seq: ' + reason);
// }
if (typeof console !== 'undefined' && console.warn) {
console.warn('Suppressed error when logging to Seq: ' + reason);
}
}

class SeqSink {
Expand Down Expand Up @@ -84,8 +84,8 @@ class SeqSink {

const body = localStorage.getItem(storageKey);
requests[storageKey] = postToSeq(this.url, this.apiKey, this.compact, body)
.catch(reason => this.suppressErrors ? logSuppressedError(reason) : Promise.reject(reason))
.then(() => localStorage.removeItem(k));
.then(() => localStorage.removeItem(k))
.catch(reason => this.suppressErrors ? logSuppressedError(reason) : Promise.reject(reason));
}
}

Expand Down Expand Up @@ -148,15 +148,10 @@ class SeqSink {
}

return postToSeq(this.url, this.apiKey, this.compact, body, done)
.catch(reason => this.suppressErrors ? logSuppressedError(reason) : Promise.reject(reason))
.then(response => response && response.json()
.then(json => this.updateLogLevel(json))
.then(() => {
if (storageKey) {
localStorage.removeItem(storageKey);
}
})
);
.then(response => response.json())
.then(json => this.updateLogLevel(json))
.then(() => { if (storageKey) localStorage.removeItem(storageKey) })
.catch(reason => this.suppressErrors ? logSuppressedError(reason) : Promise.reject(reason));
}

updateLogLevel(response) {
Expand Down

0 comments on commit cb7f2d3

Please sign in to comment.