 
   # validating req params
   { error, token, username } = validateRequest req
-  return res.status(error.statusCode).send(error.message)  if error
+  return sendApiError res, error  if error
 
   account  = null
   apiToken = null

    ->
      # checking if token is valid
      JApiToken.one { code : token }, (err, apiToken_) ->
        return res.status(500).send 'an error occurred'  if err
        return res.status(400).send 'invalid token!'     unless apiToken_
        apiToken = apiToken_
        queue.next()

    ->
      # checking if user exists
      JAccount.one { 'profile.nickname' : username }, (err, account_) ->
        return res.status(500).send 'an error occurred'  if err
        return res.status(400).send 'invalid username!'  unless account_
        account = account_
        queue.next()


  token        = null
  { username } = req.body

  unless username
    return { error : apiErrors.invalidUsername }

  unless token = checkAuthorizationBearerHeader req
    return { error : apiErrors.unauthorizedRequest }

  return { error : null, token, username }

