   robot.error (err, msg) ->
     robot.logger.error 'Uncaught exception:', err
 
+  errorHandler = (err, res) ->
+    if err
+      robot.logger.error (CONN_ERRORS[err.code] || CONN_ERRORS['default']) err
+
   # define basic clients
   httpclients =
     actiontypes: robot.http('http://localhost:9501').path('/actiontypes')


  # init for actions
  httpclients.actions
  .get(errorHandler robot) (err, res, body) ->
    actions = JSON.parse body
    robot.brain.set 'actions', _.zipObject _.map(actions, 'name'), actions

  httpclients.actiontypes
    .get(errorHandler robot) (err, res, body) ->
      actiontypes = JSON.parse body
      robot.brain.set 'actiontypes', _.zipObject _.map(actiontypes, 'name'), actiontypes



    httpclients.actionexecutions
      .header('Content-Type', 'application/json')
      .post(JSON.stringify(payload), errorHandler) (err, res, body) ->
        staction_execution = JSON.parse(body)

        unless res.statusCode is 201
          msg.send "Action has failed to run"

        unless staction_execution.status is 'complete'
          msg.send "Action has failed to execute"
