     ->
       # checking if token is valid
       JApiToken.one { code : token }, (err, apiToken_) ->
-
-        if err
-          return callback { statusCode : 500, message : 'an error occurred' }
-
-        unless apiToken_
-          return callback { statusCode : 400, message : 'invalid token!' }
+        return callback apiErrors.internalError    if err
+        return callback apiErrors.invalidApiToken  unless apiToken_
 
         apiToken = apiToken_
         queue.next()

      username or= "#{apiToken.group.substring(0, 4)}#{hat(32)}"
      # checking if username is available
      JUser.usernameAvailable username, (err, { kodingUser, forbidden }) ->

        if err
          return callback { statusCode : 500, message : 'an error occurred' }

        if kodingUser or forbidden
          return callback { statusCode : 400, message : 'username is not available' }

        queue.next()

    ->
      # checking if apiToken is enabled for the Group
      JGroup.one { slug : apiToken.group }, (err, group) ->

        if err
          return callback { statusCode : 500, message : 'an error occurred' }

        unless group
          return callback { statusCode : 400, message : 'group does not exist!' }

        unless group.isApiTokenEnabled is true
          return callback { statusCode : 403, message : 'api token usage is not enabled for this group' }

        queue.next()

    -> callback null, { apiToken, username }


    ->
      validateData { token, username }, (err, data) ->
        return sendApiError res, err  if err
        { username, apiToken } = data
        queue.next()

