         }
     }
     
+    func webSocket(webSocket: SRWebSocket!, didFailWithError error: NSError!) {
+        reconnectWebSocket()
+    }
+    
     func webSocket(webSocket: SRWebSocket!, didReceiveMessage message: AnyObject!) {
         if let s = message as? String {
             if let data = s.dataUsingEncoding(NSUTF8StringEncoding) {

                    if let data = JSON as? [String : AnyObject] {
                        let u = User.sharedInstance
                        u.setValuesForKeysWithDictionary(data)
                        onSuccess(u)
                    } else {
                        if let fail = onFailure {

                        fail("Invalid server response")
                    }
                } else {
                    
                    if let data = JSON as? [[String : AnyObject]] {
                        
