         
         ws.event.close = { code, reason, clean in
             print("WEBSOCKET: CLOSED")
+            completion()
         }
+        
         ws.event.error = { error in
             print("WEBSOCKET ERROR: \(error)")
+            failure(MojioError(code: "WebSocketError", message: "Error received \(error)"))
         }
         ws.event.open = {
             print("WEBSOCKET: OPENED")


public class WSClient : RestClient {
    
    public func watch(completion: ((AnyObject) -> Void), failure: (NSError) -> Void) -> WebSocket {
        
        let request = NSMutableURLRequest(URL: NSURL(string:super.pushUrl!)!)
        if let accessToken : String = super.accessToken() {

                    if let data = text.dataUsingEncoding(NSUTF8StringEncoding) {
                        if let dict = try! NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions()) as? NSDictionary {
                            if let obj = super.parseDict(dict) {
                                next(obj)
                            }
                        }
                    }
