Merge branch 'sk-handle-analytics-absence'

This commit is contained in:
Shane Kilkelly 2017-03-22 09:35:16 +00:00
commit 4e6553ebcc
3 changed files with 20 additions and 4 deletions

View file

@ -1,7 +1,14 @@
AnalyticsManager = require "./AnalyticsManager"
Errors = require "../Errors/Errors"
module.exports = AnalyticsController =
recordEvent: (req, res, next) ->
AnalyticsManager.recordEvent req.session?.user?._id, req.params.event, req.body, (error) ->
return next(error) if error?
if error?
if error instanceof Errors.ServiceNotConfiguredError
# ignore, no-op
return res.send(204)
else
return next(error)
res.send 204

View file

@ -2,6 +2,7 @@ settings = require "settings-sharelatex"
logger = require "logger-sharelatex"
_ = require "underscore"
request = require "request"
Errors = require '../Errors/Errors'
makeRequest = (opts, callback)->
@ -10,8 +11,7 @@ makeRequest = (opts, callback)->
opts.url = "#{settings.apis.analytics.url}#{urlPath}"
request opts, callback
else
callback()
callback(new Errors.ServiceNotConfiguredError('Analytics service not configured'))
module.exports =

View file

@ -5,5 +5,14 @@ NotFoundError = (message) ->
return error
NotFoundError.prototype.__proto__ = Error.prototype
ServiceNotConfiguredError = (message) ->
error = new Error(message)
error.name = "ServiceNotConfiguredError"
error.__proto__ = ServiceNotConfiguredError.prototype
return error
module.exports = Errors =
NotFoundError: NotFoundError
NotFoundError: NotFoundError
ServiceNotConfiguredError: ServiceNotConfiguredError