fix(errors): Send 400 errors from the Nylas API to Sentry

This commit is contained in:
Ben Gotow 2015-09-08 18:09:11 -07:00
parent 53252fcb97
commit 94226ad9be
3 changed files with 21 additions and 6 deletions

View file

@ -272,10 +272,9 @@ class Atom extends Model
Promise.onPossiblyUnhandledRejection (error) =>
error.stack = convertStackTrace(error.stack, sourceMapCache)
eventObject = {message: error.message, originalError: error}
# API Errors are a normal part of life and are logged to the API
# history panel. We ignore these errors and do not report them to Sentry.
# API Errors are logged to Sentry only under certain circumstances,
# and are logged directly from the NylasAPI class.
if error instanceof APIError
return
@ -289,9 +288,13 @@ class Atom extends Model
console.warn(error)
console.warn(error.stack)
@emitter.emit('will-throw-error', eventObject)
@emit('uncaught-error', error.message, null, null, null, error)
@emitter.emit('did-throw-error', eventObject)
@emitError(error)
emitError: (error) ->
eventObject = {message: error.message, originalError: error}
@emitter.emit('will-throw-error', eventObject)
@emit('uncaught-error', error.message, null, null, null, error)
@emitter.emit('did-throw-error', eventObject)
###
Section: Event Subscription

View file

@ -262,6 +262,16 @@ module.exports = ErrorReporter = (function() {
ErrorReporter.prototype.reportError = function(err, metadata) {
if (this.inSpecMode || this.inDevMode) { return };
// Never send user auth tokens
if (err.requestOptions && err.requestOptions.auth) {
delete err.requestOptions['auth'];
}
// Never send message bodies
if (err.requestOptions && err.requestOptions.body && err.requestOptions.body.body) {
delete err.requestOptions.body['body'];
}
this.client.captureError(err, {
extra: metadata,
tags: {

View file

@ -181,6 +181,8 @@ class NylasAPI
handlePromise = @_handleModel404(options.url)
if err.response.statusCode is 401
handlePromise = @_handle401(options.url)
if err.response.statusCode is 400
atom.emitError(err)
handlePromise.finally ->
Promise.reject(err)