       .header("content-type","application/json")
       .header("content-length",json.length)
       .put(json) (err, res, body) ->
+        if err?
+          return robot.emit 'error', err, msg
         json_body = null
         switch res.statusCode
           when 200 then json_body = JSON.parse(body)

      .headers(Authorization: auth, Accept: 'application/json')
      .header("content-length",0)
      .delete() (err, res, body) ->
        json_body = null
        switch res.statusCode
          when 204, 200

      .header("content-type","application/json")
      .header("content-length",json.length)
      .post(json) (err, res, body) ->
        if err?
          return robot.emit 'error', err, msg
        json_body = null
        switch res.statusCode
          when 201 then json_body = JSON.parse(body)
