Fixing most lint errors in error-logger

Summary: Cleaning up almost all the linting errors in the logger

Test Plan: ... run the build

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3605
This commit is contained in:
Tomasz Finc 2017-01-07 13:12:12 -08:00
parent afdc5a3ef9
commit 2c0fd79707

View file

@ -4,13 +4,11 @@
// paths don't work properly.
//
var raven = require('raven');
var path = require('path');
const raven = require('raven');
var app = (process.type === 'renderer') ? require('electron').remote.app : require('electron').app;
var tmpPath = app.getPath('temp');
const app = (process.type === 'renderer') ? require('electron').remote.app : require('electron').app;
module.exports = (function() {
module.exports = (function (...args) {
function ErrorReporter(modes) {
this.reportError = this.reportError.bind(this)
this.inSpecMode = modes.inSpecMode
@ -21,14 +19,14 @@ module.exports = (function() {
this._setupSentry();
}
const bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
const bind = function (fn, me) { return function () { return fn.apply(me, ...args); }; };
this.onDidLogAPIError = bind(this.onDidLogAPIError, this);
}
ErrorReporter.prototype.onDidLogAPIError = function(error, statusCode, message) {
ErrorReporter.prototype.onDidLogAPIError = function (error, statusCode, message) {
}
ErrorReporter.prototype._setupSentry = function() {
ErrorReporter.prototype._setupSentry = function () {
// Initialize the Sentry connector
this.client = new raven.Client('https://7a32cb0189ff4595a55c98ffb7939c46:f791c3c402b343068bed056b8b504dd5@sentry.nylas.com/4');
@ -36,26 +34,26 @@ module.exports = (function() {
this.client.setUserContext({id: NylasEnv.config.get('nylas.identity.id')});
}
this.client.on('error', function(e) {
this.client.on('error', function (e) {
console.log(e.reason);
console.log(e.statusCode);
return console.log(e.response);
});
}
ErrorReporter.prototype.reportError = function(err, extra) {
ErrorReporter.prototype.reportError = function (err, extra) {
if (this.inSpecMode || this.inDevMode) { return }
// It's possible for there to be more than 1 sentry capture object.
// If an error comes from multiple plugins, we report a unique event
// for each plugin since we want to group by individual pluginId
const captureObjects = this._prepareSentryCaptureObjects(err, extra)
for (var i = 0; i < captureObjects.length; i++) {
for (let i = 0; i < captureObjects.length; i++) {
this.client.captureError(err, captureObjects[i])
}
};
ErrorReporter.prototype.getVersion = function() {
ErrorReporter.prototype.getVersion = function () {
if (typeof NylasEnv !== 'undefined' && NylasEnv) {
return NylasEnv.getVersion();
}
@ -65,39 +63,39 @@ module.exports = (function() {
return null;
};
ErrorReporter.prototype._prepareSentryCaptureObjects = function(error, extra) {
ErrorReporter.prototype._prepareSentryCaptureObjects = function (error, extra) {
let captureObjects = this._prepareSentryCaptureObjects(error, extra)
// Never send user auth tokens
if (error.requestOptions && error.requestOptions.auth) {
delete error.requestOptions['auth'];
delete error.requestOptions.auth;
}
// Never send message bodies
if (error.requestOptions && error.requestOptions.body && error.requestOptions.body.body) {
delete error.requestOptions.body['body'];
delete error.requestOptions.body.body;
}
if (extra && extra.pluginIds && extra.pluginIds.length > 0) {
captureObjects = [];
for (var i = 0; i < extra.pluginIds.length; i ++) {
for (let i = 0; i < extra.pluginIds.length; i++) {
captureObjects.push({
extra: extra,
tags: {
'platform': process.platform,
'version': this.getVersion(),
'pluginId': extra.pluginIds[i]
}
platform: process.platform,
version: this.getVersion(),
pluginId: extra.pluginIds[i],
},
});
}
return captureObjects
} else {
return [{
extra: extra,
tags: {
'platform': process.platform,
'version': this.getVersion()
}
}]
}
return [{
extra: extra,
tags: {
platform: process.platform,
version: this.getVersion(),
},
}]
}
return ErrorReporter;