     res.json(201, competitionMembership)
     console.log("[HTTP] 201: joined competition: #{competitionMembership}")
   )
-  .fail((err) ->
-    errorMsg = "failed to join competition. reason: #{err}"
-    res.json(500, {error: errorMsg})
-    console.error("[HTTP] 500: #{errorMsg}")
-    console.error(err.stack)
+  .fail((err) =>
+    @handleApiError(
+      res,
+      err,
+      errorMsg: "failed to join competition"
+    )
   )
   .done()
 

    res.json(200, competition)
    console.log "[HTTP] 200: ended competition: #{competition}"
  )
  .fail((err) ->
    errorMsg = "failed to end competition. reason: #{err}"
    res.json(500, {error: errorMsg})
    console.error("[HTTP] 500: #{errorMsg}")
    console.error(err.stack)
  )
  .done()


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

