     @handleApiError(
       res,
       err,
-      errorMsg: "failed to create user"
+      errorMsg: "failed to create user (name=#{name})"
     )
   )
   .done()

  )

createUser = (req, res) ->
  @api.createUser(req.body.name)
  .then((user) ->
    res.json(201, user)
    console.log("[HTTP] 201: created user: #{user}")

  )

startCompetition = (req, res) ->
  userId = req.body.userId
  name = req.body.name

  @api.startCompetition(userId, name)
  .then((competition) ->
    res.json(201, competition)
    console.log("[HTTP] 201: started competition: #{competition}")
  )
  .fail((err) =>
    @handleApiError(res, err, errorMsg: "failed to start competition (userId=#{userId}, name=#{name})")
  )
  .done()

endCompetition = (req, res) ->
  competitionId = req.params.competitionId

  @api.endCompetition(competitionId)
  .then((competition) ->
    res.json(200, competition)
    console.log "[HTTP] 200: ended competition: #{competition}"
  )
  .fail((err) =>
    @handleApiError(res, err, errorMsg: "failed to end competition (competitionId=#{competitionId})")
  )
  .done()

joinCompetition = (req, res) ->
  userId = req.body.userId
  competitionId = req.params.competitionId

  @api.joinCompetition(userId, competitionId)
  .then((competitionMembership) ->
    res.json(201, competitionMembership)
    console.log("[HTTP] 201: joined competition: #{competitionMembership}")
  )
  .fail((err) =>
    @handleApiError(res, err,
      errorMsg: "failed to join competition (userId=#{userId}, competitionId=#{competitionId})"
    )
  )
  .done()

