       # 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) ->

        # when there is an error in the fetchClient, it returns message in it
        if client.message
          console.error JSON.stringify { req, client }
          return res.status(500).send client.message

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



        # send HTTP 400 if somehow alreadyMember is true but user doesnt exist
        if alreadyMember and errorMessage is unknownUsernameError
          return next generateAPIError 400, unknownUsernameError

        # setting alreadyMember to true if error is not unknownUsernameError
        # ignoring other errors here since our only concern is checking if user exists
        alreadyMember = errorMessage isnt unknownUsernameError
        next()

  ]

  async.series queue, (err) ->
    return res.status(err.status).send err.message  if err

    # generating callback function to be used in both login and convert
    createGroup = createGroupKallback client, req, res, body

    if alreadyMember
    then JUser.login client.sessionToken, body, createGroup
    else JUser.convert client, body, createGroup


validateTeamInvitation = (teamAccessCode, callback) ->
