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

  daisy queue



validateRequest = (req) ->

  token = null
  { username, email, firstName, lastName } = req.body

  errors =
    invalidRequest      :
      statusCode        : 400
      message           : 'invalid request'
    unauthorizedRequest :
      statusCode        : 401
      message           : 'unauthorized request'

  unless email
    return { error : errors.invalidRequest }

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

  return { error : null, token, username, email, firstName, lastName }


hat                                = require 'hat'
koding                             = require '../../bongo'
apiErrors                          = require './errors'
{ daisy }                          = require 'bongo'
{ getClientId
  handleClientIdNotFound
  checkAuthorizationBearerHeader } = require '../../helpers'
{ sendApiError
  sendApiResponse
  checkApiTokenAvailability }       = require './helpers'


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

