         }
     }
 
+    /**
+     Determine if a WebSockets error is the result of an authentication failure. This is
+     particularly helpful when we want to intercept authentication failures and retry
+     the connection with an updated token before returning the error to the user.
+
+     - parameter error: A WebSockets error that may have been caused by an authentication failure.
+
+     - returns: `true` if the given error is the result of an authentication failure; false,
+        otherwise.
+     */
     private func isAuthenticationFailure(error: NSError?) -> Bool {
-        guard let error = error,
-              let description = error.userInfo[NSLocalizedDescriptionKey] as? String else
-        {
+        guard let error = error else {
+            return false
+        }
+
+        guard let description = error.userInfo[NSLocalizedDescriptionKey] as? String else {
             return false
         }
 

import Foundation
import Starscream

class WatsonWebSocket {

    private let authStrategy: AuthenticationStrategy

            self.operations.suspended = true
            self.isConnecting = false
            if self.isAuthenticationFailure(error) {
                self.connectWithToken()
            } else if let error = error {
                self.isClosedByError = true
