mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-26 20:34:02 +00:00
Merge pull request #6 from sharelatex/bg-avoid-reporting-errors-more-than-once
avoid reporting the same error object more than once
This commit is contained in:
commit
adb081f556
2 changed files with 21 additions and 0 deletions
|
@ -19,6 +19,9 @@ module.exports = Logger =
|
||||||
attributes = {err: new Error(attributes)}
|
attributes = {err: new Error(attributes)}
|
||||||
# extract any error object
|
# extract any error object
|
||||||
error = attributes.err or attributes.error
|
error = attributes.err or attributes.error
|
||||||
|
# avoid reporting errors twice
|
||||||
|
for key, value of attributes
|
||||||
|
return if value instanceof Error && value.reportedToSentry
|
||||||
# include our log message in the error report
|
# include our log message in the error report
|
||||||
if not error?
|
if not error?
|
||||||
error = {message: message} if typeof message is 'string'
|
error = {message: message} if typeof message is 'string'
|
||||||
|
@ -50,6 +53,9 @@ module.exports = Logger =
|
||||||
# send the error to sentry
|
# send the error to sentry
|
||||||
try
|
try
|
||||||
@raven.captureException(error, {tags: tags, extra: extra, level: level})
|
@raven.captureException(error, {tags: tags, extra: extra, level: level})
|
||||||
|
# put a flag on the errors to avoid reporting them multiple times
|
||||||
|
for key, value of attributes
|
||||||
|
value.reportedToSentry = true if value instanceof Error
|
||||||
catch
|
catch
|
||||||
return # ignore any errors
|
return # ignore any errors
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
# run this with
|
||||||
|
# ./node_modules/.bin/mocha --reporter tap --compilers coffee:coffee-script/register test/unit/coffee/loggingManagerTests.coffee
|
||||||
|
|
||||||
require('coffee-script')
|
require('coffee-script')
|
||||||
chai = require('chai')
|
chai = require('chai')
|
||||||
should = chai.should()
|
should = chai.should()
|
||||||
|
@ -24,6 +27,18 @@ describe 'logger.error', ->
|
||||||
@logger.error {foo:'bar'}, "message"
|
@logger.error {foo:'bar'}, "message"
|
||||||
@captureException.called.should.equal true
|
@captureException.called.should.equal true
|
||||||
|
|
||||||
|
it 'should report the same error to sentry only once', () ->
|
||||||
|
error1 = new Error('this is the error')
|
||||||
|
@logger.error {foo: error1}, "first message"
|
||||||
|
@logger.error {bar: error1}, "second message"
|
||||||
|
@captureException.callCount.should.equal 1
|
||||||
|
|
||||||
|
it 'should report two different errors to sentry individually', () ->
|
||||||
|
error1 = new Error('this is the error')
|
||||||
|
error2 = new Error('this is the error')
|
||||||
|
@logger.error {foo: error1}, "first message"
|
||||||
|
@logger.error {bar: error2}, "second message"
|
||||||
|
@captureException.callCount.should.equal 2
|
||||||
|
|
||||||
it 'for multiple errors should only report a maximum of 5 errors to sentry', () ->
|
it 'for multiple errors should only report a maximum of 5 errors to sentry', () ->
|
||||||
@logger.error {foo:'bar'}, "message"
|
@logger.error {foo:'bar'}, "message"
|
||||||
|
|
Loading…
Reference in a new issue