       # checking if group slug is same with the username
       if slug.toLowerCase?() is body.username?.toLowerCase?()
         message = 'Sorry, your group domain and your username can not be the same!'
-        return  res.status(400).send message
+        return next generateAPIError 400, message
 
       # checking if group slug was already used
       JGroup.one { slug }, (err, group) ->
-        return res.status(500).send 'an error occured'  if err
-        return res.status(403).send "Sorry,
+        return next generateAPIError 500, 'an error occured'  if err
+        return next generateAPIError 403, "Sorry,
           Team URL '#{slug}.#{hostname}' is already in use"  if group
         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]



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

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