Fix up makeRequest, so it copes with analytics.url being un-configured.

This commit is contained in:
Shane Kilkelly 2016-11-16 14:40:38 +00:00
parent 5b3cd7ed2b
commit f9774141b1

View file

@ -4,8 +4,10 @@ _ = require "underscore"
request = require "request"
makeRequest: (opts, callback)->
makeRequest = (opts, callback)->
if settings.apis?.analytics?.url?
urlPath = opts.url
opts.url = "#{settings.apis.analytics.url}#{urlPath}"
request opts, callback
else
callback()
@ -25,7 +27,7 @@ module.exports =
json:true
method:"POST"
timeout:1000
url: "#{settings.apis.analytics.url}/user/#{user_id}/event"
url: "/user/#{user_id}/event"
makeRequest opts, callback
@ -36,11 +38,11 @@ module.exports =
json:true
method:"POST"
timeout:1000
url: "#{settings.apis.analytics.url}/user/#{user_id}/event/last_occurnace"
url: "/user/#{user_id}/event/last_occurnace"
makeRequest opts, (err, response, body)->
if err?
console.log response, opts
logger.err {user_id, err}, "error getting last occurance of event"
return callback err
else
return callback null, body
return callback null, body