       # if we dont have teamaccesscode just continue
 
       validateTeamInvitation teamAccessCode, (err) ->
-        return res.status(400).send err  if err
+        return next generateAPIError 400, err  if err
         next()
 
     (next) ->


{ uniq }                                = require 'underscore'
{ hostname, environment }               = KONFIG
{ getClientId, handleClientIdNotFound } = require './../helpers'
{ validateTeamDomain }                  = require '../../../../workers/social/lib/social/models/user/validators'

module.exports = (req, res, next) ->

        # when there is an error in the fetchClient, it returns message in it
        if client.message
          console.error JSON.stringify { req, client }
          return next generateAPIError 500, client.message

        client.clientIP = (clientIPAddress.split ',')[0]

